I would like to insert data to the last row of my table. But it’s doing it 4 rows later. Here my code :
' ------ FR020 -----
'Variable pour trouver la dernière ligne
Dim DernLigne As Long
DernLigne = Range("A1:Q1").End(xlUp).Row
' Insérer valeur FR020 en A
Range("A1" & DernLigne).Value = "FR020"
' Insérer valeur 03700 en D
Range("D1" & DernLigne).Value = "03700"
'Insérer valeur 59800019FR en E
Range("E1" & DernLigne).Value = "59800019FR"
Here the table :
CodePudding user response:
You need to go xlUp from the very last row of the worksheet Range("A" & Rows.Count)
Any you need to change Range("A1" & DernLigne) into Range("A" & DernLigne)
Dim DernLigne As Long
DernLigne = Range("A" & Rows.Count).End(xlUp).Row 1 'remove the 1 to overwrite the last data row
' Insérer valeur FR020 en A
Range("A" & DernLigne).Value = "FR020"
' Insérer valeur 03700 en D
Range("D" & DernLigne).Value = "03700"
'Insérer valeur 59800019FR en E
Range("E" & DernLigne).Value = "59800019FR"
The problem was that Range("A1:Q1").End(xlUp).Row resulted in row 1
and this Range("A1" & DernLigne) appended this 1 to A1 so it got Range("A11").

