Oui effectivement c'est sur le même programme mais pas sur la même fonction.
Je vous explique le processus derrière tout ca.
J'importe un fichier PDF dans la feuille "Cost list".
Ensuite je veux remplir toutes les case de la feuille "Estimation Rapide" selon les données de la feuille "Cost List"
Le problème c'est que je peut avoir de 1 à 10 composition différente (Code de produit)
Ainsi je me suit créé un range variable "Plage_Compos" que j'ai défini selon des mots (Walls et Detailed by components) qui se retrouve sur mon importation de PDF "Cost list".
Par contre, si l'importation ne contient que 2 code produits je ne veut pas que l'on définisse "Compos_3 à 10"
Voici le code complet (ou j'en suis rendu) et la feuil Cost List
Si vous pouvez aussi m'indiqué mes erreurs ou des simplifications cela serait apprécié.
MERCI !
Sub Autofill()
Dim Compos_1 As String
Dim Compos_2 As String
Dim Compos_3 As String
Dim Compos_4 As String
Dim Compos_5 As String
Dim Compos_6 As String
Dim Compos_7 As String
Dim Compos_8 As String
Dim Compos_9 As String
Dim Compos_10 As String
Dim Début_Ligne As Long
Dim Début_Colonne As Long
Dim Fin_Ligne As Long
Dim Fin_Colonne As Long
Dim Plage_Compos As Range
With Worksheets("Cost list").Range("A1:G500")
.Find("Project").Offset(0, 1).Copy _
Destination:=Worksheets("Estimation Rapide").Range("T3:X3") 'Nom du projet
.Find("Client").Offset(0, 1).Copy _
Destination:=Worksheets("Estimation Rapide").Range("F3:Q3") ' Nom du client
'----------------------------------Range_des_Compos---------------------------------------
Début_Ligne = .Find("Walls").Offset(1, 0).Row
Début_Colonne = .Find("Walls").Offset(1, 0).Column
Fin_Ligne = .Find("Detailed by components").Offset(-1, 6).Row
Fin_Colonne = .Find("Detailed by components").Offset(-1, 6).Column
Set Plage_Compos = .Range(Cells(Début_Ligne, Début_Colonne), Cells(Fin_Ligne, Fin_Colonne))
End With
'----------------------------------Compos_1---------------------------------------
With Worksheets("Cost list")
Compos_1 = .Range("Plage_Compos").Cells(1, 1) 'Compos_1
Worksheets("Estimation rapide").Range("C6") = Mid(Compos_1, 1, 1)
Worksheets("Estimation rapide").Range("D6") = Mid(Compos_1, 2, 1)
Worksheets("Estimation rapide").Range("E6") = Mid(Compos_1, 3, 1)
Worksheets("Estimation rapide").Range("F6") = Mid(Compos_1, 4, 1)
Worksheets("Estimation rapide").Range("G6") = Mid(Compos_1, 5, 1)
Worksheets("Estimation rapide").Range("H6") = Mid(Compos_1, 6, 1)
Worksheets("Estimation rapide").Range("I6") = Mid(Compos_1, 7, 1)
Worksheets("Estimation rapide").Range("J6") = Mid(Compos_1, 8, 1)
Worksheets("Estimation rapide").Range("K6") = Mid(Compos_1, 9, 1)
Worksheets("Estimation rapide").Range("L6") = Mid(Compos_1, 10, 1)
Worksheets("Estimation rapide").Range("M6") = Mid(Compos_1, 11, 1)
Worksheets("Estimation rapide").Range("N6") = Mid(Compos_1, 12, 1)
Worksheets("Estimation rapide").Range("O6") = Mid(Compos_1, 13, 1)
.Range("Plage_Compos").Cells(1, 3).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Q6:Q7") 'Pi lin de la Compos 1
.Range("Plage_Compos").Cells(1, 7).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Z6:Z7") 'Cost de la Compos 1
.Range("Plage_Compos").Cells(1, 6).Copy _
Destination:=Worksheets("Estimation Rapide").Range("AA6:AA7") '$/pi2 de la Compos 1
'----------------------------------Compos_2---------------------------------------
Compos_2 = .Range("Plage_Compos").Cells(2, 1) 'Compos_2
Worksheets("Estimation rapide").Range("C8") = Mid(Compos_2, 1, 1)
Worksheets("Estimation rapide").Range("D8") = Mid(Compos_2, 2, 1)
Worksheets("Estimation rapide").Range("E8") = Mid(Compos_2, 3, 1)
Worksheets("Estimation rapide").Range("F8") = Mid(Compos_2, 4, 1)
Worksheets("Estimation rapide").Range("G8") = Mid(Compos_2, 5, 1)
Worksheets("Estimation rapide").Range("H8") = Mid(Compos_2, 6, 1)
Worksheets("Estimation rapide").Range("I8") = Mid(Compos_2, 7, 1)
Worksheets("Estimation rapide").Range("J8") = Mid(Compos_2, 8, 1)
Worksheets("Estimation rapide").Range("K8") = Mid(Compos_2, 9, 1)
Worksheets("Estimation rapide").Range("L8") = Mid(Compos_2, 10, 1)
Worksheets("Estimation rapide").Range("M8") = Mid(Compos_2, 11, 1)
Worksheets("Estimation rapide").Range("N8") = Mid(Compos_2, 12, 1)
Worksheets("Estimation rapide").Range("O8") = Mid(Compos_2, 13, 1)
.Range("Plage_Compos").Cells(2, 3).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Q8:Q9") 'Pi lin de la Compos 2
.Range("Plage_Compos").Cells(2, 7).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Z8:Z9") 'Cost de la Compos 2
.Range("Plage_Compos").Cells(2, 6).Copy _
Destination:=Worksheets("Estimation Rapide").Range("AA8:AA9") '$/pi2 de la Compos 2
'----------------------------------Compos_3---------------------------------------
Compos_3 = .Range("Plage_Compos").Cells(3, 1) 'Compos_3
Worksheets("Estimation rapide").Range("C10") = Mid(Compos_3, 1, 1)
Worksheets("Estimation rapide").Range("D10") = Mid(Compos_3, 2, 1)
Worksheets("Estimation rapide").Range("E10") = Mid(Compos_3, 3, 1)
Worksheets("Estimation rapide").Range("F10") = Mid(Compos_3, 4, 1)
Worksheets("Estimation rapide").Range("G10") = Mid(Compos_3, 5, 1)
Worksheets("Estimation rapide").Range("H10") = Mid(Compos_3, 6, 1)
Worksheets("Estimation rapide").Range("I10") = Mid(Compos_3, 7, 1)
Worksheets("Estimation rapide").Range("J10") = Mid(Compos_3, 8, 1)
Worksheets("Estimation rapide").Range("K10") = Mid(Compos_3, 9, 1)
Worksheets("Estimation rapide").Range("L10") = Mid(Compos_3, 10, 1)
Worksheets("Estimation rapide").Range("M10") = Mid(Compos_3, 11, 1)
Worksheets("Estimation rapide").Range("N10") = Mid(Compos_3, 12, 1)
Worksheets("Estimation rapide").Range("O10") = Mid(Compos_3, 13, 1)
.Range("Plage_Compos").Cells(3, 3).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Q10:Q10") 'Pi lin de la Compos 3
.Range("Plage_Compos").Cells(3, 7).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Z10:Z10") 'Cost de la Compos 3
.Range("Plage_Compos").Cells(3, 6).Copy _
Destination:=Worksheets("Estimation Rapide").Range("AA10:AA10") '$/pi2 de la Compos 3
'----------------------------------Compos_4---------------------------------------
'----------------------------------Compos_5---------------------------------------
'----------------------------------Compos_6---------------------------------------
'----------------------------------Compos_7---------------------------------------
'----------------------------------Compos_8---------------------------------------
'----------------------------------Compos_9---------------------------------------
'----------------------------------Compos_10---------------------------------------
.Find(After:=.Range(.Find("Studs").Address), What:="SubTotal", SearchOrder:=xlByRows).Offset(0, 1).Copy 'Coût Studs
Worksheets("Estimation Rapide").Range("Q26").PasteSpecial xlPasteValues
.Find(After:=.Range(.Find("Headers").Address), What:="Subtotal", SearchOrder:=xlByRows).Offset(0, 1).Copy 'Coût Headers
Worksheets("Estimation Rapide").Range("Q27").PasteSpecial xlPasteValues
.Find(After:=.Range(.Find("Posts").Address), What:="Subtotal", SearchOrder:=xlByRows).Offset(0, 1).Copy 'Coût Posts
Worksheets("Estimation Rapide").Range("Q28").PasteSpecial xlPasteValues
.Find(After:=.Range(.Find("Sheathing").Address), What:="Subtotal", SearchOrder:=xlByRows).Offset(0, 1).Copy 'Coût Seathing
Worksheets("Estimation Rapide").Range("Q29").PasteSpecial xlPasteValues
.Find(After:=.Range(.Find("Insulation").Address), What:="R-20", SearchOrder:=xlByRows).Offset(0, 6).Copy 'Coût Laine (A Modifier pour R-28)
Worksheets("Estimation Rapide").Range("Q30").PasteSpecial xlPasteValues
.Find(After:=.Range(.Find("Insulation").Address), What:="Isoclad", SearchOrder:=xlByRows).Offset(0, 6).Copy 'Coût Isoclad (A Modifier si plusieur Isoclad différent)
Worksheets("Estimation Rapide").Range("Q32").PasteSpecial xlPasteValues
.Find(After:=.Range(.Find("Insulation").Address), What:="Iso R", SearchOrder:=xlByRows).Offset(0, 6).Copy 'Coût IsoRplus (A Modifier si plusieur IsoRplus différent)
Worksheets("Estimation Rapide").Range("Q32").PasteSpecial xlPasteValues
.Find(After:=.Range(.Find("Strapping").Address), What:="Subtotal", SearchOrder:=xlByRows).Offset(0, 1).Copy 'Coût Strapping
Worksheets("Estimation Rapide").Range("Q34").PasteSpecial xlPasteValues
.Find("Sill Foam").Offset(0, 6).Copy
Worksheets("Estimation Rapide").Range("Q35").PasteSpecial xlPasteValues 'Coût Sill Foam
.Find("Fasteners").Offset(0, 6).Copy
Worksheets("Estimation Rapide").Range("Q36").PasteSpecial xlPasteValues 'Coût Fasteners
.Find("Sealant").Offset(0, 6).Copy
Worksheets("Estimation Rapide").Range("Q37").PasteSpecial xlPasteValues 'Coût Sealant
End With
End Sub