VBA - Autofill
Hello le forum,
J'ai encore une fois besoin de votre aide, j'ai beau chercher à droite et à gauche, je ne comprend pas la source de mon erreur... Surtout que la syntaxe est correcte
Voilà mon code :
Private Sub Vlookup()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
If ThisWorkbook.Sheets("supplier 1").Range("B1").Value = "" Then Exit Sub
Dim mwb As Workbook
Set mwb = Workbooks.Open(FileName:=ThisWorkbook.Sheets("supplier 1").Range("B1").Value)
With ThisWorkbook.Worksheets("Supplier 1")
.Range("C3").Formula = "=IFERROR(VLOOKUP($B3,'[" & mwb.Name & "]Global sourcing prices'!$D:$AG, MATCH(C$1,'[" & mwb.Name & "]Global sourcing prices'!$D$3:$AG$3,0), 0),0)"
.Range("C3").AutoFill Destination:=Range("C3:C2000")
.Range("C3:C2000").AutoFill Destination:=Range("C3:X2000")
Application.Calculation = xlCalculationAutomatic
.Range("C3:X2000").Value = Range("C3:X2000").Value
End With
mwb.Close False
Set mwb = Nothing
Application.ScreenUpdating = True
End SubJ'ai un soucis sur l'autofill --> la méthode autofill de la classe range a échoué sur la ligne de code ci dessous:
.Range("C3").AutoFill Destination:=Range("C3:C2000") Si quelqu'un a une solution, ca serai top !!
Merci d'avance et bonne soirée à tous
Erwan
Bonsoir,
Surtout que la syntaxe est correcte
Hum !
Et ça c'est bien de la syntaxe !
ThisWorkbook n'est pas le classeur actif lors de l'Autofill, et Range("C3:C2000") réfère à la feuille active du classeur actif...
Cordialement.
Bonjour,
Et oui, il te faut affiler les Range :
With ThisWorkbook.Worksheets("Supplier 1")
.Range("C3").Formula = "=IFERROR(VLOOKUP($B3,'[" & mwb.Name & "]Global sourcing prices'!$D:$AG, MATCH(C$1,'[" & mwb.Name & "]Global sourcing prices'!$D$3:$AG$3,0), 0),0)"
.Range("C3").AutoFill .Range("C3:C2000")
.Range("C3:C2000").AutoFill .Range("C3:X2000")
Application.Calculation = xlCalculationAutomatic
.Range("C3:X2000").Value = .Range("C3:X2000").Value
End WithHello
J'avoue, je suis encore débutant donc j'ai du mal à me passer de l’enregistreur pour certaine formule mais j'essaye de corriger ça
Donc, du coup j'ai juste ajouté .activate avant ma formule et tout fonctionne
With ThisWorkbook.Worksheets("Supplier 1")
.Activate
.Range("C3").Formula = "=IFERROR(VLOOKUP($B3,'[" & mwb.Name & "]Global sourcing prices'!$D:$AG, MATCH(C$1,'[" & mwb.Name & "]Global sourcing prices'!$D$3:$AG$3,0), 0),0)"
.Range("C3").AutoFill Destination:=Range("C3:C2000")
.Range("C3:C2000").AutoFill Destination:=Range("C3:X2000")
Application.Calculation = xlCalculationAutomatic
.Range("C3:X2000").Value = Range("C3:X2000").Value
End WithVous êtes géniaux, merci les gars !
Passez une bonne journée
Pas besoin d'Activate, il te suffit de mettre un point devant Range pour qu'il soit affilié à la feuille "Supplier 1" puisque tu utilises With ... End With :
With ThisWorkbook.Worksheets("Supplier 1")
.Range("C3").AutoFill .Range("C3:C2000")
'...
'...
End Withen mettant un point devant Range("C3:C2000") tu l'affilie à la feuille "Supplier 1" With ThisWorkbook.Worksheets("Supplier 1")
Ahhh ok, je comprend mieux mieux le pourquoi du .range ! Je change mon code...
Merci beaucoup