Macro qui stoppe en cours de compilation

Bonjour,

Je voudrais savoir pourquoi quand je renseigne tout les textbox il ne m'éxécute pas la macro jusqu'à la fin ?

Il y a t-il une histoire de longueur de macro ?

Merci

Private Sub CommandButton1_Click()
   Dim LastRow As Object

   Set LastRow = Feuil1.Range("a65536").End(xlUp)

   LastRow.Offset(1, 0).Value = TextBox1.Text
   LastRow.Offset(1, 1).Value = TextBox2.Text
   LastRow.Offset(1, 2).Value = TextBox3.Text
   LastRow.Offset(1, 3).Value = TextBox4.Text
   LastRow.Offset(1, 5).Value = TextBox5.Text
   LastRow.Offset(1, 6).Value = TextBox6.Text
   LastRow.Offset(1, 7).Value = TextBox7.Text
   LastRow.Offset(1, 8).Value = TextBox8.Text
   LastRow.Offset(1, 9).Value = TextBox9.Text
   LastRow.Offset(1, 10).Value = TextBox10.Text
   LastRow.Offset(1, 11).Value = TextBox11.Text
   LastRow.Offset(1, 12).Value = TextBox12.Text
   LastRow.Offset(1, 13).Value = TextBox13.Text
   LastRow.Offset(1, 14).Value = TextBox14.Text
   LastRow.Offset(1, 15).Value = TextBox15.Text
   LastRow.Offset(1, 16).Value = TextBox16.Text
   LastRow.Offset(1, 17).Value = TextBox17.Text
   LastRow.Offset(1, 18).Value = TextBox18.Text
   LastRow.Offset(1, 19).Value = TextBox19.Text
   LastRow.Offset(1, 20).Value = TextBox20.Text
   LastRow.Offset(1, 21).Value = TextBox21.Text
   LastRow.Offset(1, 22).Value = TextBox22.Text
   LastRow.Offset(1, 23).Value = TextBox23.Text
   LastRow.Offset(1, 24).Value = TextBox24.Text
   LastRow.Offset(1, 25).Value = TextBox25.Text
   LastRow.Offset(1, 26).Value = TextBox26.Text
   LastRow.Offset(1, 27).Value = TextBox27.Text
   LastRow.Offset(1, 28).Value = TextBox28.Text
   LastRow.Offset(1, 29).Value = TextBox29.Text
   LastRow.Offset(1, 30).Value = TextBox30.Text
   LastRow.Offset(1, 31).Value = TextBox31.Text
   LastRow.Offset(1, 32).Value = TextBox32.Text
   LastRow.Offset(1, 33).Value = TextBox33.Text
   LastRow.Offset(1, 34).Value = TextBox34.Text
   LastRow.Offset(1, 35).Value = TextBox35.Text
   LastRow.Offset(1, 36).Value = TextBox36.Text
   LastRow.Offset(1, 37).Value = TextBox37.Text
   LastRow.Offset(1, 38).Value = TextBox38.Text

 If TextBox1 = "" Then
   LastRow.Offset(1, 0).Value = "/"
   End If

   If TextBox2 = "" Then
   LastRow.Offset(1, 1).Value = "/"
   End If

   If TextBox3 = "" Then
   LastRow.Offset(1, 2).Value = "/"
   End If

   If TextBox4 = "" Then
   LastRow.Offset(1, 3).Value = "/"
   End If

   If TextBox5 = "" Then
   LastRow.Offset(1, 5).Value = "/"
   End If

   If TextBox6 = "" Then
   LastRow.Offset(1, 6).Value = "/"
   End If

   If TextBox7 = "" Then
   LastRow.Offset(1, 7).Value = "/"
   End If

   If TextBox8 = "" Then
   LastRow.Offset(1, 8).Value = "/"
   End If

   If TextBox9 = "" Then
   LastRow.Offset(1, 9).Value = "/"
   End If

   If TextBox10 = "" Then
   LastRow.Offset(1, 10).Value = "/"
   End If

   If TextBox11 = "" Then
   LastRow.Offset(1, 11).Value = "/"
   End If

   If TextBox12 = "" Then
   LastRow.Offset(1, 12).Value = "/"
   End If

   If TextBox13 = "" Then
   LastRow.Offset(1, 13).Value = "/"
   End If

   If TextBox14 = "" Then
   LastRow.Offset(1, 14).Value = "/"
   End If

   If TextBox15 = "" Then
   LastRow.Offset(1, 15).Value = "/"
   End If

   If TextBox16 = "" Then
   LastRow.Offset(1, 16).Value = "/"
   End If

   If TextBox17 = "" Then
   LastRow.Offset(1, 17).Value = "/"
   End If

   If TextBox18 = "" Then
   LastRow.Offset(1, 18).Value = "/"
   End If

   If TextBox19 = "" Then
   LastRow.Offset(1, 19).Value = "/"
   End If

   If TextBox20 = "" Then
   LastRow.Offset(1, 20).Value = "/"
   End If

   If TextBox21 = "" Then
   LastRow.Offset(1, 21).Value = "/"
   End If

   If TextBox22 = "" Then
   LastRow.Offset(1, 22).Value = "/"
   End If

   If TextBox23 = "" Then
   LastRow.Offset(1, 23).Value = "/"
   End If

   If TextBox24 = "" Then
   LastRow.Offset(1, 24).Value = "/"
   End If

   If TextBox25 = "" Then
   LastRow.Offset(1, 25).Value = "/"
   End If

   If TextBox26 = "" Then
   LastRow.Offset(1, 26).Value = "/"
   End If

   If TextBox27 = "" Then
   LastRow.Offset(1, 27).Value = "/"
   End If

   If TextBox28 = "" Then
   LastRow.Offset(1, 28).Value = "/"
   End If

   If TextBox29 = "" Then
   LastRow.Offset(1, 29).Value = "/"
   End If

   If TextBox30 = "" Then
   LastRow.Offset(1, 30).Value = "/"
   End If

   If TextBox31 = "" Then
   LastRow.Offset(1, 31).Value = "/"
   End If

   If TextBox32 = "" Then
   LastRow.Offset(1, 32).Value = "/"
   End If

   If TextBox33 = "" Then
   LastRow.Offset(1, 33).Value = "/"
   End If

   If TextBox34 = "" Then
   LastRow.Offset(1, 34).Value = "/"
   End If

   If TextBox35 = "" Then
   LastRow.Offset(1, 35).Value = "/"
   End If

   If TextBox36 = "" Then
   LastRow.Offset(1, 36).Value = "/"
   End If

   If TextBox37 = "" Then
   LastRow.Offset(1, 37).Value = "/"

   If TextBox38 = "" Then
   LastRow.Offset(1, 38).Value = "/"
   End If

      For i = 1 To 6
        If Controls("OptionButton" & i) = True Then
            LastRow.Offset(1, 4).Value = Controls("OptionButton" & i).Caption
        End If
   Next i

   MsgBox "Vous venez d'insérer un nouveau QMOS à la base de données"

   Response = MsgBox("Voulez vous enregistrer un autre QMOS ?", _
      vbYesNo)

   If Response = vbYes Then
      TextBox1.Text = ""
      TextBox2.Text = ""
      TextBox3.Text = ""
      TextBox4.Text = ""
      TextBox5.Text = ""
      TextBox6.Text = ""
      TextBox7.Text = ""
      TextBox8.Text = ""
      TextBox9.Text = ""
      TextBox10.Text = ""
      TextBox11.Text = ""
      TextBox12.Text = ""
      TextBox13.Text = ""
      TextBox14.Text = ""
      TextBox15.Text = ""
      TextBox16.Text = ""
      TextBox17.Text = ""
      TextBox18.Text = ""
      TextBox19.Text = ""
      TextBox20.Text = ""
      TextBox21.Text = ""
      TextBox22.Text = ""
      TextBox23.Text = ""
      TextBox24.Text = ""
      TextBox25.Text = ""
      TextBox26.Text = ""
      TextBox27.Text = ""
      TextBox28.Text = ""
      TextBox29.Text = ""
      TextBox30.Text = ""
      TextBox31.Text = ""
      TextBox32.Text = ""
      TextBox33.Text = ""
      TextBox34.Text = ""
      TextBox35.Text = ""
      TextBox36.Text = ""
      TextBox37.Text = ""
      TextBox38.Text = ""
      TextBox39.Text = ""

      TextBox1.SetFocus

   Else
      Unload Me
   End If
End If
End Sub

Bonjour,

conformément aux règles de la charte de ce forum - et du reste comme dans l'autre forum - utiliser

l'icône dédiée au balisage de code !

Ensuite corriger le titre de ce sujet en adéquation avec la problématique …

Sinon suivre la progression du code en mode pas à pas via la touche F8 tout en contrôlant la fenêtre des Variables locales

Bonjour

Déjà, tu pourrais boucler sur tes Textboxes de 1 à 38 avec

Private Sub CommandButton1_Click()
       Dim Derlign As Byte
       Dim n As Byte
    Derlign = Feuil1.Range("a65536").End(xlUp).Row

For n = 1 To 38

        If UserForm1.Controls("TextBox" & n).Value <> "" Then
        Cells(Derlign, n + 1).Value = UserForm1.Controls("TextBox" & n).Value
        ElseIf UserForm1.Controls("TextBox" & n).Value = "" Then
        Cells(Derlign, n + 1).Value = "/"
        End If

Next
End Sub
Next

De même, pour effacer tous les TextBoxes d'un coup

If Response = vbYes Then
              Dim objControl As Control
        For Each objControl In UserForm1.Controls
            If TypeOf objControl Is msforms.TextBox Then
                objControl.Text = ""
            End If
        Next

Cordialement

Oui merci ! C'est ok il est vrai que cette macro pouvait être bien raccourci !

Rebonjour je viens juste de m'apercevoir qu'il y a une petite erreur dans mon code, il y a un saut de cellule :

 LastRow.Offset(1, 3).Value = TextBox4.Text
   LastRow.Offset(1, 5).Value = TextBox5.Text

Du coup tout se décale...

j'ai essayer ceci mais il y a une incompatibilité de type..

Private Sub CommandButton1_Click()
   Dim LastRow As Object

   Set LastRow = Feuil1.Range("a65536").End(xlUp)

   LastRow.Offset(1, 0).Value = TextBox1.Text
   LastRow.Offset(1, 1).Value = TextBox2.Text
   LastRow.Offset(1, 2).Value = TextBox3.Text
   LastRow.Offset(1, 3).Value = TextBox4.Text

Dim n As Byte
Dim LastRow1 As Byte
Set LastRow1 = Feuil1.Range("a65536").End(xlUp)

  For n = 5 To 38

        If UserForm2.Controls("TextBox" & n + 5).Value <> "" Then
        Cells(LastRow1, n + 5).Value = UserForm2.Controls("TextBox" & n + 5).Value
        ElseIf UserForm2.Controls("TextBox" & n).Value = "" Then
        Cells(LastRow1, n).Value = "/"
        End If

Next   

Il y une erreur d'Objet... je suis novice

Rechercher des sujets similaires à "macro qui stoppe cours compilation"