Erreur sur code
Bonjour voici j'ai une erreur sur mon code vba surligné en vert
Merci a vous
'Correspond au programme du bouton Ajouter
Private Sub CommandButton5_Click()
Dim L As Integer, f
If ComboBox2 <> "" Then
If MsgBox("Confirmez-vous l'ajout de ce nouveau client dan la fiche " & ComboBox2 & " ?", _
vbYesNo, "demande de confirmationd'ajout") = vbYes Then
Set f = Sheets(ComboBox2.Value)
GoTo suite
Else
Set f = Sheets("base_client")
End If
End If
If MsgBox("Confirmez-vous l'ajout de ce contrat?", vbYesNo, "demande de confirmationd'ajout") = vbYes Then
suite:
L = f.Range("A65536").End(xlUp).Row + 1
f.Range("A" & L).Value = TextBox1
f.Range("B" & L).Value = TextBox2
f.Range("C" & L).Value = TextBox3
f.Range("D" & L).Value = TextBox4
f.Range("E" & L).Value = TextBox5
f.Range("F" & L).Value = TextBox6
f.Range("G" & L).Value = TextBox7
f.Range("H" & L).Value = TextBox8
f.Range("I" & L).Value = TextBox9
f.Range("J" & L).Value = TextBox10
f.Range("K" & L).Value = TextBox11
f.Range("L" & L).Value = TextBox12
f.Range("M" & L).Value = TextBox13
f.Range("N" & L).Value = TextBox14
'Range("O" & L).Value = TextBox15
'Range("P" & L).Value = TextBox16
'Range("Q" & L).Value = TextBox16
'Range("R" & L).Value = TextBox17
'Range("S" & L).Value = TextBox18
'Range("T" & L).Value = TextBox19
'Range("U" & L).Value = TextBox20
'Range("V" & L).Value = TextBox21
'Range("W" & L).Value = TextBox22
End If
Unload Me
UserForm1.Show
End SubBonjour,
En remplaçant
Dim L As Integer, fpar
Dim L as long, f as Worksheetsa devrait régler le problème.
Ensuite
L = f.Range("A65536").End(xlUp).Row + 1n'est pas approprié, vous avez noté travaillé sous Excel 2007 or 65536 est le nombre limite de lignes d'Excel 2003.
Execel 2007 dispose de 1048576 lignes.
Pour une plus grande compatibilité entre les versions (à moins que vous êtes certains de ne pas dépasser ce nombre de lignes
L = f.Range("A" & Rows.Count).End(xlUp).Row + 1Vous pourriez également alléger votre code comme ceci si l'ordre est toujours le même que celui indiqué dans votre code original :
'Correspond au programme du bouton Ajouter
Private Sub CommandButton5_Click()
Dim L as long, f as Worksheet
If ComboBox2 <> "" Then
If MsgBox("Confirmez-vous l'ajout de ce nouveau client dan la fiche " & ComboBox2 & " ?", _
vbYesNo, "demande de confirmationd'ajout") = vbYes Then
Set f = Sheets(ComboBox2.Value)
GoTo suite
Else
Set f = Sheets("base_client")
End If
End If
If MsgBox("Confirmez-vous l'ajout de ce contrat?", vbYesNo, "demande de confirmationd'ajout") = vbYes Then
suite:
L = f.Range("A" & Rows.Count).End(xlUp).Row + 1
For i = 1 To 14
f.Cells(L, i).Value = Controls("Textbox" & i)
Next i
End If
Set f = Nothing
Unload Me
UserForm1.Show
End Subbonjour fred,
Merci pour l'info et la solution, le code fonctionne