Bonjour,
Désolée de poser une question qui a déjà été traitée plusieurs fois mais je ne trouve pas la solution à mon problème et je suis novice.
Dans le cadre d'une création d'entreprise je prépare des fichiers clients.
J'aimerais lorsque je rentre un nouveau client que les données s'enregistrent automatiquement dans un fichier clients fermé.
Voici ce que j'ai écrit
Private Sub CommandButton2_Click()
Dim WB1 As Workbook, WB2 As Workbook
Dim ws1 As Worksheet, ws2 As Worksheet
Dim j As Long
Dim chemin As String, fichier As String
Set WB1 = ActiveWorkbook
Set ws1 = WB1.Sheets("Informations client")
Set WB2 = ThisWorkbook
chemin = "C:\Users\aurel\Desktop\BCT\Fichier clients\"
fichier = "Fichier clients.xlsx"
Workbooks.Open chemin & fichier
Set ws2 = WB2.Sheets("Clients")
j = ws2.Range("A" & Rows.Count).End(xlUp).Row + 1
ws2.Range("A" & j).Value = ws1.Range("A19").Value
ws2.Range("B" & j).Value = ws1.Range("B2").Value
ws2.Range("C" & j).Value = ws1.Range("B3").Value
ws2.Range("D" & j).Value = ws1.Range("B6").Value
ws2.Range("E" & j).Value = ws1.Range("B7").Value
Application.ScreenUpdating = True
End Sub
Lorsque je l'exécute il me met "erreur d'exécution "9" l'indice n'appartient pas à la sélection". Cela concernerait ws2. Je ne comprends pas pourquoi.
Je vous remercie pour votre aide.