Microsoft 365 Simplification de Code

MarcMad

XLDnaute Nouveau
Bonjour,

J'ai enfin réussi a faire fonctionner mon code parcontre, il est laid et long.
J'aimerais le simplifier quelque peu avec votre aide !

Merci


Sub PDF_Import()

On Error GoTo Fin

Dim Able2ExtracPath As String
Dim PathAndFileName As String
Dim ShellPathName As String

With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = False
.InitialFileName = "X:\2020\Dossier client"
.Show
PathAndFileName = .SelectedItems(1)
End With

Able2ExtracPath = "C:\Program Files\Investintech.com Inc\Able2Extract Professional 15.0\Able2extractPro.exe"
ShellPathName = Able2ExtracPath & " """ & PathAndFileName & """"

Call Shell(pathname:=ShellPathName, windowstyle:=vbNormalFocus)

Application.Wait Now + TimeValue("0:00:03")

SendKeys "^a"
SendKeys "^c"

Application.Wait Now + TimeValue("0:00:03")

With Worksheets("Cost List")

.Range("A1").Select
.Paste
.Range("A1:G500").Replace What:="$", Replacement:=0

End With

Call Shell("TaskKill /F/IM Able2extractPro.exe", vbHide)

Fin:

End Sub

Sub Autofill()

Dim Compos_1_R, Compos_2_R, Compos_3_R, Compos_4_R, Compos_5_R, Compos_6_R, Compos_7_R, Compos_8_R, Compos_9_R, Compos_10_R As Long
Dim Compos_1, Compos_2, Compos_3, Compos_4, Compos_5, Compos_6, Compos_7, Compos_8, Compos_9, Compos_10 As String
Dim Début_Ligne, Début_Colonne, Fin_Ligne, Fin_Colonne As Long
Dim Plage_Compos As Range

'----------------------------------Range_des_Compos---------------------------------------

With Worksheets("Cost list").Range("A1:G500")

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

'----------------------------------Détermination des Compos---------------------------------

With Worksheets("Cost list").Range("Plage_Compos")

Compos_1_R = .Row 'Ligne de la Compos_1
Compos_2_R = .Row + 1 'Ligne de la Compos_2
Compos_3_R = .Row + 2 'Ligne de la Compos_3
Compos_4_R = .Row + 3 'Ligne de la Compos_4
Compos_5_R = .Row + 4 'Ligne de la Compos_5
Compos_6_R = .Row + 5 'Ligne de la Compos_6
Compos_7_R = .Row + 6 'Ligne de la Compos_7
Compos_8_R = .Row + 7 'Ligne de la Compos_8
Compos_9_R = .Row + 8 'Ligne de la Compos_9
Compos_10_R = .Row + 9 'Ligne de la Compos_10

'----------------------------------Compos_1-------------------------------------------------

If Compos_1_R > Fin_Ligne Then
GoTo Compos_2
Else
Compos_1 = .Cells(Compos_1_R - Début_Ligne + 1, 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("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("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)

.Cells(Compos_1_R - Début_Ligne + 1, 3).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Q6:Q7") 'Pi lin de la Compos_1

.Cells(Compos_1_R - Début_Ligne + 1, 6).Copy _
Destination:=Worksheets("Estimation Rapide").Range("AA6:AA7") '$/pi2 de la Compos_1

.Cells(Compos_1_R - Début_Ligne + 1, 7).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Z6:Z7") 'Cost de la Compos_1

End If

'----------------------------------Compos_2-------------------------------------------------

Compos_2:
If Compos_2_R > Fin_Ligne Then
GoTo Compos_3
Else
Compos_2 = .Cells(Compos_2_R - Début_Ligne + 1, 1)

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("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("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)

.Cells(Compos_2_R - Début_Ligne + 1, 3).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Q8:Q9") 'Pi lin de la Compos_2

.Cells(Compos_2_R - Début_Ligne + 1, 6).Copy _
Destination:=Worksheets("Estimation Rapide").Range("AA8:AA9") '$/pi2 de la Compos_2

.Cells(Compos_2_R - Début_Ligne + 1, 7).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Z8:Z9") 'Cost de la Compos_2

End If

'----------------------------------Compos_3-------------------------------------------------

Compos_3:
If Compos_3_R > Fin_Ligne Then
GoTo Compos_4
Else
Compos_3 = .Cells(Compos_3_R - Début_Ligne + 1, 1)

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("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("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)

.Cells(Compos_3_R - Début_Ligne + 1, 3).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Q10:Q11") 'Pi lin de la Compos_3

.Cells(Compos_3_R - Début_Ligne + 1, 6).Copy _
Destination:=Worksheets("Estimation Rapide").Range("AA10:AA11") '$/pi2 de la Compos_3

.Cells(Compos_3_R - Début_Ligne + 1, 7).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Z10:Z11") 'Cost de la Compos_3

End If

'----------------------------------Compos_4-------------------------------------------------

Compos_4:
If Compos_4_R > Fin_Ligne Then
GoTo Compos_5
Else
Compos_4 = .Cells(Compos_4_R - Début_Ligne + 1, 1)

Worksheets("Estimation rapide").Range("C12") = Mid(Compos_4, 1, 1)
Worksheets("Estimation rapide").Range("D12") = Mid(Compos_4, 2, 1)
Worksheets("Estimation rapide").Range("E12") = Mid(Compos_4, 3, 1)
Worksheets("Estimation rapide").Range("F12") = Mid(Compos_4, 4, 1)

Worksheets("Estimation rapide").Range("H12") = Mid(Compos_4, 6, 1)
Worksheets("Estimation rapide").Range("I12") = Mid(Compos_4, 7, 1)
Worksheets("Estimation rapide").Range("J12") = Mid(Compos_4, 8, 1)
Worksheets("Estimation rapide").Range("K12") = Mid(Compos_4, 9, 1)

Worksheets("Estimation rapide").Range("M12") = Mid(Compos_4, 11, 1)
Worksheets("Estimation rapide").Range("N12") = Mid(Compos_4, 12, 1)
Worksheets("Estimation rapide").Range("O12") = Mid(Compos_4, 13, 1)

.Cells(Compos_4_R - Début_Ligne + 1, 3).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Q12:Q13") 'Pi lin de la Compos_4

.Cells(Compos_4_R - Début_Ligne + 1, 6).Copy _
Destination:=Worksheets("Estimation Rapide").Range("AA12:AA13") '$/pi2 de la Compos_4

.Cells(Compos_4_R - Début_Ligne + 1, 7).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Z12:Z13") 'Cost de la Compos_4


End If

'----------------------------------Compos_5-------------------------------------------------

Compos_5:
If Compos_5_R > Fin_Ligne Then
GoTo Compos_6
Else
Compos_5 = .Cells(Compos_5_R - Début_Ligne + 1, 1)

Worksheets("Estimation rapide").Range("C14") = Mid(Compos_5, 1, 1)
Worksheets("Estimation rapide").Range("D14") = Mid(Compos_5, 2, 1)
Worksheets("Estimation rapide").Range("E14") = Mid(Compos_5, 3, 1)
Worksheets("Estimation rapide").Range("F14") = Mid(Compos_5, 4, 1)

Worksheets("Estimation rapide").Range("H14") = Mid(Compos_5, 6, 1)
Worksheets("Estimation rapide").Range("I14") = Mid(Compos_5, 7, 1)
Worksheets("Estimation rapide").Range("J14") = Mid(Compos_5, 8, 1)
Worksheets("Estimation rapide").Range("K14") = Mid(Compos_5, 9, 1)

Worksheets("Estimation rapide").Range("M14") = Mid(Compos_5, 11, 1)
Worksheets("Estimation rapide").Range("N14") = Mid(Compos_5, 12, 1)
Worksheets("Estimation rapide").Range("O14") = Mid(Compos_5, 13, 1)

.Cells(Compos_5_R - Début_Ligne + 1, 3).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Q14:Q15") 'Pi lin de la Compos_5

.Cells(Compos_5_R - Début_Ligne + 1, 6).Copy _
Destination:=Worksheets("Estimation Rapide").Range("AA14:AA15") '$/pi2 de la Compos_5

.Cells(Compos_5_R - Début_Ligne + 1, 7).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Z14:Z15") 'Cost de la Compos_5

End If

'----------------------------------Compos_6-------------------------------------------------

Compos_6:
If Compos_6_R > Fin_Ligne Then
GoTo Compos_7
Else
Compos_6 = .Cells(Compos_6_R - Début_Ligne + 1, 1)

Worksheets("Estimation rapide").Range("C16") = Mid(Compos_6, 1, 1)
Worksheets("Estimation rapide").Range("D16") = Mid(Compos_6, 2, 1)
Worksheets("Estimation rapide").Range("E16") = Mid(Compos_6, 3, 1)
Worksheets("Estimation rapide").Range("F16") = Mid(Compos_6, 4, 1)

Worksheets("Estimation rapide").Range("H16") = Mid(Compos_6, 6, 1)
Worksheets("Estimation rapide").Range("I16") = Mid(Compos_6, 7, 1)
Worksheets("Estimation rapide").Range("J16") = Mid(Compos_6, 8, 1)
Worksheets("Estimation rapide").Range("K16") = Mid(Compos_6, 9, 1)

Worksheets("Estimation rapide").Range("M16") = Mid(Compos_6, 11, 1)
Worksheets("Estimation rapide").Range("N16") = Mid(Compos_6, 12, 1)
Worksheets("Estimation rapide").Range("O16") = Mid(Compos_6, 13, 1)

.Cells(Compos_6_R - Début_Ligne + 1, 3).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Q16:Q17") 'Pi lin de la Compos_6

.Cells(Compos_6_R - Début_Ligne + 1, 6).Copy _
Destination:=Worksheets("Estimation Rapide").Range("AA16:AA17") '$/pi2 de la Compos_6

.Cells(Compos_6_R - Début_Ligne + 1, 7).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Z16:Z17") 'Cost de la Compos_6

End If

'----------------------------------Compos_7-------------------------------------------------

Compos_7:
If Compos_7_R > Fin_Ligne Then
GoTo Compos_8
Else
Compos_7 = .Cells(Compos_7_R - Début_Ligne + 1, 1)

Worksheets("Estimation rapide").Range("C18") = Mid(Compos_7, 1, 1)
Worksheets("Estimation rapide").Range("D18") = Mid(Compos_7, 2, 1)
Worksheets("Estimation rapide").Range("E18") = Mid(Compos_7, 3, 1)
Worksheets("Estimation rapide").Range("F18") = Mid(Compos_7, 4, 1)

Worksheets("Estimation rapide").Range("H18") = Mid(Compos_7, 6, 1)
Worksheets("Estimation rapide").Range("I18") = Mid(Compos_7, 7, 1)
Worksheets("Estimation rapide").Range("J18") = Mid(Compos_7, 8, 1)
Worksheets("Estimation rapide").Range("K18") = Mid(Compos_7, 9, 1)

Worksheets("Estimation rapide").Range("M18") = Mid(Compos_7, 11, 1)
Worksheets("Estimation rapide").Range("N18") = Mid(Compos_7, 12, 1)
Worksheets("Estimation rapide").Range("O18") = Mid(Compos_7, 13, 1)

.Cells(Compos_7_R - Début_Ligne + 1, 3).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Q18:Q19") 'Pi lin de la Compos_7

.Cells(Compos_7_R - Début_Ligne + 1, 6).Copy _
Destination:=Worksheets("Estimation Rapide").Range("AA18:AA19") '$/pi2 de la Compos_7

.Cells(Compos_7_R - Début_Ligne + 1, 7).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Z18:Z19") 'Cost de la Compos_7

End If

'----------------------------------Compos_8-------------------------------------------------

Compos_8:
If Compos_8_R > Fin_Ligne Then
GoTo Compos_9
Else
Compos_8 = .Cells(Compos_8_R - Début_Ligne + 1, 1)

Worksheets("Estimation rapide").Range("C20") = Mid(Compos_8, 1, 1)
Worksheets("Estimation rapide").Range("D20") = Mid(Compos_8, 2, 1)
Worksheets("Estimation rapide").Range("E20") = Mid(Compos_8, 3, 1)
Worksheets("Estimation rapide").Range("F20") = Mid(Compos_8, 4, 1)

Worksheets("Estimation rapide").Range("H20") = Mid(Compos_8, 6, 1)
Worksheets("Estimation rapide").Range("I20") = Mid(Compos_8, 7, 1)
Worksheets("Estimation rapide").Range("J20") = Mid(Compos_8, 8, 1)
Worksheets("Estimation rapide").Range("K20") = Mid(Compos_8, 9, 1)

Worksheets("Estimation rapide").Range("M20") = Mid(Compos_8, 11, 1)
Worksheets("Estimation rapide").Range("N20") = Mid(Compos_8, 12, 1)
Worksheets("Estimation rapide").Range("O20") = Mid(Compos_8, 13, 1)

.Cells(Compos_8_R - Début_Ligne + 1, 3).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Q20") 'Pi lin de la Compos_8

.Cells(Compos_8_R - Début_Ligne + 1, 6).Copy _
Destination:=Worksheets("Estimation Rapide").Range("AA20") '$/pi2 de la Compos_8

.Cells(Compos_8_R - Début_Ligne + 1, 7).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Z20") 'Cost de la Compos_8

End If

'----------------------------------Compos_9-------------------------------------------------

Compos_9:
If Compos_9_R > Fin_Ligne Then
GoTo Compos_10
Else
Compos_9 = .Cells(Compos_9_R - Début_Ligne + 1, 1)

Worksheets("Estimation rapide").Range("C21") = Mid(Compos_9, 1, 1)
Worksheets("Estimation rapide").Range("D21") = Mid(Compos_9, 2, 1)
Worksheets("Estimation rapide").Range("E21") = Mid(Compos_9, 3, 1)
Worksheets("Estimation rapide").Range("F21") = Mid(Compos_9, 4, 1)

Worksheets("Estimation rapide").Range("H21") = Mid(Compos_9, 6, 1)
Worksheets("Estimation rapide").Range("I21") = Mid(Compos_9, 7, 1)
Worksheets("Estimation rapide").Range("J21") = Mid(Compos_9, 8, 1)
Worksheets("Estimation rapide").Range("K21") = Mid(Compos_9, 9, 1)

Worksheets("Estimation rapide").Range("M21") = Mid(Compos_9, 11, 1)
Worksheets("Estimation rapide").Range("N21") = Mid(Compos_9, 12, 1)
Worksheets("Estimation rapide").Range("O21") = Mid(Compos_9, 13, 1)

.Cells(Compos_9_R - Début_Ligne + 1, 3).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Q21") 'Pi lin de la Compos_9

.Cells(Compos_9_R - Début_Ligne + 1, 6).Copy _
Destination:=Worksheets("Estimation Rapide").Range("AA21") '$/pi2 de la Compos_9

.Cells(Compos_9_R - Début_Ligne + 1, 7).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Z21") 'Cost de la Compos_9

End If

'----------------------------------Compos_10-------------------------------------------------

Compos_10:
If Compos_10_R > Fin_Ligne Then
GoTo Fin_des_Compos
Else
Compos_10 = .Cells(Compos_10_R - Début_Ligne + 1, 1)

Worksheets("Estimation rapide").Range("C22") = Mid(Compos_10, 1, 1)
Worksheets("Estimation rapide").Range("D22") = Mid(Compos_10, 2, 1)
Worksheets("Estimation rapide").Range("E22") = Mid(Compos_10, 3, 1)
Worksheets("Estimation rapide").Range("F22") = Mid(Compos_10, 4, 1)

Worksheets("Estimation rapide").Range("H22") = Mid(Compos_10, 6, 1)
Worksheets("Estimation rapide").Range("I22") = Mid(Compos_10, 7, 1)
Worksheets("Estimation rapide").Range("J22") = Mid(Compos_10, 8, 1)
Worksheets("Estimation rapide").Range("K22") = Mid(Compos_10, 9, 1)

Worksheets("Estimation rapide").Range("M22") = Mid(Compos_10, 11, 1)
Worksheets("Estimation rapide").Range("N22") = Mid(Compos_10, 12, 1)
Worksheets("Estimation rapide").Range("O22") = Mid(Compos_10, 13, 1)

.Cells(Compos_10_R - Début_Ligne + 1, 3).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Q22") 'Pi lin de la Compos_10

.Cells(Compos_10_R - Début_Ligne + 1, 6).Copy _
Destination:=Worksheets("Estimation Rapide").Range("AA22") '$/pi2 de la Compos_10

.Cells(Compos_10_R - Début_Ligne + 1, 7).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Z22") 'Cost de la Compos_10

End If

Fin_des_Compos:

End With

'----------------------------------Autre_Informations--------------------------------------------

With Worksheets("Cost list").Range("A1:G500")

On Error GoTo Client

.Find("Project").Offset(0, 1).Copy _
Destination:=Worksheets("Estimation Rapide").Range("T3:X3") 'Nom du projet

Client:
On Error GoTo Studs

.Find("Client").Offset(0, 1).Copy _
Destination:=Worksheets("Estimation Rapide").Range("F3:Q3") ' Nom du client

Studs:
On Error GoTo Headers

.Find(After:=.Range(.Find("Studs").Address), What:="SubTotal", SearchOrder:=xlByRows).Offset(0, 1).Copy 'Coût Studs
Worksheets("Estimation Rapide").Range("Q26").PasteSpecial xlPasteValues

Headers:
On Error GoTo Posts

.Find(After:=.Range(.Find("Headers").Address), What:="Subtotal", SearchOrder:=xlByRows).Offset(0, 1).Copy 'Coût Headers
Worksheets("Estimation Rapide").Range("Q27").PasteSpecial xlPasteValues

Posts:
On Error GoTo Sheathing

.Find(After:=.Range(.Find("Posts").Address), What:="Subtotal", SearchOrder:=xlByRows).Offset(0, 1).Copy 'Coût Posts
Worksheets("Estimation Rapide").Range("Q28").PasteSpecial xlPasteValues

Sheathing:
On Error GoTo Insulation_1

.Find(After:=.Range(.Find("Sheathing").Address), What:="Subtotal", SearchOrder:=xlByRows).Offset(0, 1).Copy 'Coût Seathing
Worksheets("Estimation Rapide").Range("Q29").PasteSpecial xlPasteValues

'----------------------------------Loop_Total_Laine--------------------------------------------

Insulation_1:
On Error GoTo Insulation_2


Dim Laine As Range
Dim FirstAddress As String
Dim Rslt As Currency

Set Laine = .Find(What:="R-", After:=.Find("Insulation"), LookAt:=xlPart)

If Not Laine Is Nothing Then
FirstAddress = Laine.Address

Do

Rslt = Rslt + Laine.Offset(0, 6).Value
Set Laine = .FindNext(Laine)
Loop While Laine.Address <> FirstAddress

Worksheets("Estimation Rapide").Range("Q30") = Rslt

End If

'----------------------------------Loop_Total_IsoClad--------------------------------------------

Insulation_2:
On Error GoTo Insulation_3

Dim IsoClad As Range
Dim FirstAddress1 As String
Dim Rslt1 As Currency

Set IsoClad = .Find(What:="Isoclad", After:=.Find("Insulation"), LookAt:=xlPart)

If Not IsoClad Is Nothing Then
FirstAddress1 = IsoClad.Address

Do

Rslt1 = Rslt1 + IsoClad.Offset(0, 6).Value
Set IsoClad = .FindNext(IsoClad)
Loop While IsoClad.Address <> FirstAddress1

Worksheets("Estimation Rapide").Range("Q31") = Rslt1

End If

'----------------------------------Loop_Total_IsoRplus--------------------------------------------

Insulation_3:
On Error GoTo Typar

Dim IsoRplus As Range
Dim FirstAddress2 As String
Dim Rslt2 As Currency

Set IsoRplus = .Find(What:="plus", After:=.Find("Insulation"), LookAt:=xlPart)

If Not IsoRplus Is Nothing Then
FirstAddress2 = IsoRplus.Address

Do

Rslt2 = Rslt2 + IsoRplus.Offset(0, 6).Value
Set IsoRplus = .FindNext(IsoRplus)
Loop While IsoRplus.Address <> FirstAddress2

Worksheets("Estimation Rapide").Range("Q32") = Rslt2

End If

'----------------------------------Suite_Autres_Info--------------------------------------------

Typar:
On Error GoTo Strapping

.Find(After:=.Range(.Find("Vapour & Air Barrier").Address), What:="Subtotal", SearchOrder:=xlByRows).Offset(0, 1).Copy 'Coût Typar
Worksheets("Estimation Rapide").Range("Q33").PasteSpecial xlPasteValues

Strapping:
On Error GoTo Sill_Foam

.Find(After:=.Range(.Find("Strapping").Address), What:="Subtotal", SearchOrder:=xlByRows).Offset(0, 1).Copy 'Coût Strapping
Worksheets("Estimation Rapide").Range("Q34").PasteSpecial xlPasteValues

Sill_Foam:
On Error GoTo Fasteners

.Find("Sill Foam").Offset(0, 6).Copy
Worksheets("Estimation Rapide").Range("Q35").PasteSpecial xlPasteValues 'Coût Sill Foam

Fasteners:
On Error GoTo Sealant

.Find("Fasteners").Offset(0, 6).Copy
Worksheets("Estimation Rapide").Range("Q36").PasteSpecial xlPasteValues 'Coût Fasteners

Sealant:
On Error GoTo Fin_Infos

.Find("Sealant").Offset(0, 6).Copy
Worksheets("Estimation Rapide").Range("Q37").PasteSpecial xlPasteValues 'Coût Sealant

Fin_Infos:

End With
End Sub
 

Nairolf

XLDnaute Accro
Salut,

Quelques propositions :
VB:
Compos_1_R = .Row 'Ligne de la Compos_1
Compos_2_R = .Row + 1 'Ligne de la Compos_2
Compos_3_R = .Row + 2 'Ligne de la Compos_3
Compos_4_R = .Row + 3 'Ligne de la Compos_4
Compos_5_R = .Row + 4 'Ligne de la Compos_5
Compos_6_R = .Row + 5 'Ligne de la Compos_6
Compos_7_R = .Row + 6 'Ligne de la Compos_7
Compos_8_R = .Row + 7 'Ligne de la Compos_8
Compos_9_R = .Row + 8 'Ligne de la Compos_9
Compos_10_R = .Row + 9 'Ligne de la Compos_10
Peut devenir ça (en faisant un dim Compos_R()) :
VB:
For i = 1 to 10
    Compos_R(i) = .Row + i - 1
Next i
 

Nairolf

XLDnaute Accro
Dans le même genre tu peux remplacer :
VB:
'----------------------------------Compos_1-------------------------------------------------

If Compos_1_R > Fin_Ligne Then
GoTo Compos_2
Else
Compos_1 = .Cells(Compos_1_R - Début_Ligne + 1, 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("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("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)

.Cells(Compos_1_R - Début_Ligne + 1, 3).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Q6:Q7") 'Pi lin de la Compos_1

.Cells(Compos_1_R - Début_Ligne + 1, 6).Copy _
Destination:=Worksheets("Estimation Rapide").Range("AA6:AA7") '$/pi2 de la Compos_1

.Cells(Compos_1_R - Début_Ligne + 1, 7).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Z6:Z7") 'Cost de la Compos_1

End If

'----------------------------------Compos_2-------------------------------------------------

Compos_2:
If Compos_2_R > Fin_Ligne Then
GoTo Compos_3
Else
Compos_2 = .Cells(Compos_2_R - Début_Ligne + 1, 1)

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("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("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)

.Cells(Compos_2_R - Début_Ligne + 1, 3).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Q8:Q9") 'Pi lin de la Compos_2

.Cells(Compos_2_R - Début_Ligne + 1, 6).Copy _
Destination:=Worksheets("Estimation Rapide").Range("AA8:AA9") '$/pi2 de la Compos_2

.Cells(Compos_2_R - Début_Ligne + 1, 7).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Z8:Z9") 'Cost de la Compos_2

End If

'----------------------------------Compos_3-------------------------------------------------

Compos_3:
If Compos_3_R > Fin_Ligne Then
GoTo Compos_4
Else
Compos_3 = .Cells(Compos_3_R - Début_Ligne + 1, 1)

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("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("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)

.Cells(Compos_3_R - Début_Ligne + 1, 3).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Q10:Q11") 'Pi lin de la Compos_3

.Cells(Compos_3_R - Début_Ligne + 1, 6).Copy _
Destination:=Worksheets("Estimation Rapide").Range("AA10:AA11") '$/pi2 de la Compos_3

.Cells(Compos_3_R - Début_Ligne + 1, 7).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Z10:Z11") 'Cost de la Compos_3

End If

'----------------------------------Compos_4-------------------------------------------------

Compos_4:
If Compos_4_R > Fin_Ligne Then
GoTo Compos_5
Else
Compos_4 = .Cells(Compos_4_R - Début_Ligne + 1, 1)

Worksheets("Estimation rapide").Range("C12") = Mid(Compos_4, 1, 1)
Worksheets("Estimation rapide").Range("D12") = Mid(Compos_4, 2, 1)
Worksheets("Estimation rapide").Range("E12") = Mid(Compos_4, 3, 1)
Worksheets("Estimation rapide").Range("F12") = Mid(Compos_4, 4, 1)

Worksheets("Estimation rapide").Range("H12") = Mid(Compos_4, 6, 1)
Worksheets("Estimation rapide").Range("I12") = Mid(Compos_4, 7, 1)
Worksheets("Estimation rapide").Range("J12") = Mid(Compos_4, 8, 1)
Worksheets("Estimation rapide").Range("K12") = Mid(Compos_4, 9, 1)

Worksheets("Estimation rapide").Range("M12") = Mid(Compos_4, 11, 1)
Worksheets("Estimation rapide").Range("N12") = Mid(Compos_4, 12, 1)
Worksheets("Estimation rapide").Range("O12") = Mid(Compos_4, 13, 1)

.Cells(Compos_4_R - Début_Ligne + 1, 3).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Q12:Q13") 'Pi lin de la Compos_4

.Cells(Compos_4_R - Début_Ligne + 1, 6).Copy _
Destination:=Worksheets("Estimation Rapide").Range("AA12:AA13") '$/pi2 de la Compos_4

.Cells(Compos_4_R - Début_Ligne + 1, 7).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Z12:Z13") 'Cost de la Compos_4


End If

'----------------------------------Compos_5-------------------------------------------------

Compos_5:
If Compos_5_R > Fin_Ligne Then
GoTo Compos_6
Else
Compos_5 = .Cells(Compos_5_R - Début_Ligne + 1, 1)

Worksheets("Estimation rapide").Range("C14") = Mid(Compos_5, 1, 1)
Worksheets("Estimation rapide").Range("D14") = Mid(Compos_5, 2, 1)
Worksheets("Estimation rapide").Range("E14") = Mid(Compos_5, 3, 1)
Worksheets("Estimation rapide").Range("F14") = Mid(Compos_5, 4, 1)

Worksheets("Estimation rapide").Range("H14") = Mid(Compos_5, 6, 1)
Worksheets("Estimation rapide").Range("I14") = Mid(Compos_5, 7, 1)
Worksheets("Estimation rapide").Range("J14") = Mid(Compos_5, 8, 1)
Worksheets("Estimation rapide").Range("K14") = Mid(Compos_5, 9, 1)

Worksheets("Estimation rapide").Range("M14") = Mid(Compos_5, 11, 1)
Worksheets("Estimation rapide").Range("N14") = Mid(Compos_5, 12, 1)
Worksheets("Estimation rapide").Range("O14") = Mid(Compos_5, 13, 1)

.Cells(Compos_5_R - Début_Ligne + 1, 3).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Q14:Q15") 'Pi lin de la Compos_5

.Cells(Compos_5_R - Début_Ligne + 1, 6).Copy _
Destination:=Worksheets("Estimation Rapide").Range("AA14:AA15") '$/pi2 de la Compos_5

.Cells(Compos_5_R - Début_Ligne + 1, 7).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Z14:Z15") 'Cost de la Compos_5

End If

'----------------------------------Compos_6-------------------------------------------------

Compos_6:
If Compos_6_R > Fin_Ligne Then
GoTo Compos_7
Else
Compos_6 = .Cells(Compos_6_R - Début_Ligne + 1, 1)

Worksheets("Estimation rapide").Range("C16") = Mid(Compos_6, 1, 1)
Worksheets("Estimation rapide").Range("D16") = Mid(Compos_6, 2, 1)
Worksheets("Estimation rapide").Range("E16") = Mid(Compos_6, 3, 1)
Worksheets("Estimation rapide").Range("F16") = Mid(Compos_6, 4, 1)

Worksheets("Estimation rapide").Range("H16") = Mid(Compos_6, 6, 1)
Worksheets("Estimation rapide").Range("I16") = Mid(Compos_6, 7, 1)
Worksheets("Estimation rapide").Range("J16") = Mid(Compos_6, 8, 1)
Worksheets("Estimation rapide").Range("K16") = Mid(Compos_6, 9, 1)

Worksheets("Estimation rapide").Range("M16") = Mid(Compos_6, 11, 1)
Worksheets("Estimation rapide").Range("N16") = Mid(Compos_6, 12, 1)
Worksheets("Estimation rapide").Range("O16") = Mid(Compos_6, 13, 1)

.Cells(Compos_6_R - Début_Ligne + 1, 3).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Q16:Q17") 'Pi lin de la Compos_6

.Cells(Compos_6_R - Début_Ligne + 1, 6).Copy _
Destination:=Worksheets("Estimation Rapide").Range("AA16:AA17") '$/pi2 de la Compos_6

.Cells(Compos_6_R - Début_Ligne + 1, 7).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Z16:Z17") 'Cost de la Compos_6

End If

'----------------------------------Compos_7-------------------------------------------------

Compos_7:
If Compos_7_R > Fin_Ligne Then
GoTo Compos_8
Else
Compos_7 = .Cells(Compos_7_R - Début_Ligne + 1, 1)

Worksheets("Estimation rapide").Range("C18") = Mid(Compos_7, 1, 1)
Worksheets("Estimation rapide").Range("D18") = Mid(Compos_7, 2, 1)
Worksheets("Estimation rapide").Range("E18") = Mid(Compos_7, 3, 1)
Worksheets("Estimation rapide").Range("F18") = Mid(Compos_7, 4, 1)

Worksheets("Estimation rapide").Range("H18") = Mid(Compos_7, 6, 1)
Worksheets("Estimation rapide").Range("I18") = Mid(Compos_7, 7, 1)
Worksheets("Estimation rapide").Range("J18") = Mid(Compos_7, 8, 1)
Worksheets("Estimation rapide").Range("K18") = Mid(Compos_7, 9, 1)

Worksheets("Estimation rapide").Range("M18") = Mid(Compos_7, 11, 1)
Worksheets("Estimation rapide").Range("N18") = Mid(Compos_7, 12, 1)
Worksheets("Estimation rapide").Range("O18") = Mid(Compos_7, 13, 1)

.Cells(Compos_7_R - Début_Ligne + 1, 3).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Q18:Q19") 'Pi lin de la Compos_7

.Cells(Compos_7_R - Début_Ligne + 1, 6).Copy _
Destination:=Worksheets("Estimation Rapide").Range("AA18:AA19") '$/pi2 de la Compos_7

.Cells(Compos_7_R - Début_Ligne + 1, 7).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Z18:Z19") 'Cost de la Compos_7

End If

'----------------------------------Compos_8-------------------------------------------------

Compos_8:
If Compos_8_R > Fin_Ligne Then
GoTo Compos_9
Else
Compos_8 = .Cells(Compos_8_R - Début_Ligne + 1, 1)

Worksheets("Estimation rapide").Range("C20") = Mid(Compos_8, 1, 1)
Worksheets("Estimation rapide").Range("D20") = Mid(Compos_8, 2, 1)
Worksheets("Estimation rapide").Range("E20") = Mid(Compos_8, 3, 1)
Worksheets("Estimation rapide").Range("F20") = Mid(Compos_8, 4, 1)

Worksheets("Estimation rapide").Range("H20") = Mid(Compos_8, 6, 1)
Worksheets("Estimation rapide").Range("I20") = Mid(Compos_8, 7, 1)
Worksheets("Estimation rapide").Range("J20") = Mid(Compos_8, 8, 1)
Worksheets("Estimation rapide").Range("K20") = Mid(Compos_8, 9, 1)

Worksheets("Estimation rapide").Range("M20") = Mid(Compos_8, 11, 1)
Worksheets("Estimation rapide").Range("N20") = Mid(Compos_8, 12, 1)
Worksheets("Estimation rapide").Range("O20") = Mid(Compos_8, 13, 1)

.Cells(Compos_8_R - Début_Ligne + 1, 3).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Q20") 'Pi lin de la Compos_8

.Cells(Compos_8_R - Début_Ligne + 1, 6).Copy _
Destination:=Worksheets("Estimation Rapide").Range("AA20") '$/pi2 de la Compos_8

.Cells(Compos_8_R - Début_Ligne + 1, 7).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Z20") 'Cost de la Compos_8

End If

'----------------------------------Compos_9-------------------------------------------------

Compos_9:
If Compos_9_R > Fin_Ligne Then
GoTo Compos_10
Else
Compos_9 = .Cells(Compos_9_R - Début_Ligne + 1, 1)

Worksheets("Estimation rapide").Range("C21") = Mid(Compos_9, 1, 1)
Worksheets("Estimation rapide").Range("D21") = Mid(Compos_9, 2, 1)
Worksheets("Estimation rapide").Range("E21") = Mid(Compos_9, 3, 1)
Worksheets("Estimation rapide").Range("F21") = Mid(Compos_9, 4, 1)

Worksheets("Estimation rapide").Range("H21") = Mid(Compos_9, 6, 1)
Worksheets("Estimation rapide").Range("I21") = Mid(Compos_9, 7, 1)
Worksheets("Estimation rapide").Range("J21") = Mid(Compos_9, 8, 1)
Worksheets("Estimation rapide").Range("K21") = Mid(Compos_9, 9, 1)

Worksheets("Estimation rapide").Range("M21") = Mid(Compos_9, 11, 1)
Worksheets("Estimation rapide").Range("N21") = Mid(Compos_9, 12, 1)
Worksheets("Estimation rapide").Range("O21") = Mid(Compos_9, 13, 1)

.Cells(Compos_9_R - Début_Ligne + 1, 3).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Q21") 'Pi lin de la Compos_9

.Cells(Compos_9_R - Début_Ligne + 1, 6).Copy _
Destination:=Worksheets("Estimation Rapide").Range("AA21") '$/pi2 de la Compos_9

.Cells(Compos_9_R - Début_Ligne + 1, 7).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Z21") 'Cost de la Compos_9

End If

'----------------------------------Compos_10-------------------------------------------------

Compos_10:
If Compos_10_R > Fin_Ligne Then
GoTo Fin_des_Compos
Else
Compos_10 = .Cells(Compos_10_R - Début_Ligne + 1, 1)

Worksheets("Estimation rapide").Range("C22") = Mid(Compos_10, 1, 1)
Worksheets("Estimation rapide").Range("D22") = Mid(Compos_10, 2, 1)
Worksheets("Estimation rapide").Range("E22") = Mid(Compos_10, 3, 1)
Worksheets("Estimation rapide").Range("F22") = Mid(Compos_10, 4, 1)

Worksheets("Estimation rapide").Range("H22") = Mid(Compos_10, 6, 1)
Worksheets("Estimation rapide").Range("I22") = Mid(Compos_10, 7, 1)
Worksheets("Estimation rapide").Range("J22") = Mid(Compos_10, 8, 1)
Worksheets("Estimation rapide").Range("K22") = Mid(Compos_10, 9, 1)

Worksheets("Estimation rapide").Range("M22") = Mid(Compos_10, 11, 1)
Worksheets("Estimation rapide").Range("N22") = Mid(Compos_10, 12, 1)
Worksheets("Estimation rapide").Range("O22") = Mid(Compos_10, 13, 1)

.Cells(Compos_10_R - Début_Ligne + 1, 3).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Q22") 'Pi lin de la Compos_10

.Cells(Compos_10_R - Début_Ligne + 1, 6).Copy _
Destination:=Worksheets("Estimation Rapide").Range("AA22") '$/pi2 de la Compos_10

.Cells(Compos_10_R - Début_Ligne + 1, 7).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Z22") 'Cost de la Compos_10

End If

Fin_des_Compos:
En faisant un dim Compos() et en mettant ce code à la place :
VB:
For j = 1 to 10

If Compos_R(j) <= Fin_Ligne Then

Compos(j) = .Cells(Compos_R(j) - Début_Ligne + 1, 1)

Worksheets("Estimation rapide").Range("C" & 4 + 2 * j) = Mid(Compos(j), 1, 1)
Worksheets("Estimation rapide").Range("D" & 4 + 2 * j) = Mid(Compos(j), 2, 1)
Worksheets("Estimation rapide").Range("E" & 4 + 2 * j) = Mid(Compos(j), 3, 1)
Worksheets("Estimation rapide").Range("F" & 4 + 2 * j) = Mid(Compos(j), 4, 1)

Worksheets("Estimation rapide").Range("H" & 4 + 2 * j) = Mid(Compos(j), 6, 1)
Worksheets("Estimation rapide").Range("I" & 4 + 2 * j) = Mid(Compos(j), 7, 1)
Worksheets("Estimation rapide").Range("J" & 4 + 2 * j) = Mid(Compos(j), 8, 1)
Worksheets("Estimation rapide").Range("K" & 4 + 2 * j) = Mid(Compos(j), 9, 1)

Worksheets("Estimation rapide").Range("M" & 4 + 2 * j) = Mid(Compos(j), 11, 1)
Worksheets("Estimation rapide").Range("N" & 4 + 2 * j) = Mid(Compos(j), 12, 1)
Worksheets("Estimation rapide").Range("O" & 4 + 2 * j) = Mid(Compos(j), 13, 1)

.Cells(Compos_R(j) - Début_Ligne + 1, 3).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Q" & 4 + 2 * j & ":Q" & 5 + 2 * j) 'Pi lin de la Compos(j)

.Cells(Compos_R(j) - Début_Ligne + 1, 6).Copy _
Destination:=Worksheets("Estimation Rapide").Range("AA" & 4 + 2 * j & ":AA" & 5 + 2 * j) '$/pi2 de la Compos(j)

.Cells(Compos_R(j) - Début_Ligne + 1, 7).Copy _
Destination:=Worksheets("Estimation Rapide").Range("Z" & 4 + 2 * j & ":Z" & 5 + 2 * j) 'Cost de la Compos(j)

End If

Next j
 

MarcMad

XLDnaute Nouveau
Merci pour les conseils, j'avais justement un peu de difficulté avec les loops.

Par contre, j'ai essayer votre première suggestion et j'ai le code d'erreur 9 - l'indice n'appartient pas à la sélection.

With Worksheets("Cost list").Range("Plage_Compos")

For i = 1 To 10

Ici ---> Compos_R(i) = .Row + i - 1

Next i
 

Discussions similaires

Réponses
3
Affichages
797
Réponses
1
Affichages
1 K

Membres actuellement en ligne

Statistiques des forums

Discussions
314 708
Messages
2 112 092
Membres
111 416
dernier inscrit
philipperoy83