VBA procédure trop grande

chinel

XLDnaute Impliqué
Salut tout le monde !


j'ai un programme en excel et vba, j'ai une userform avec des textbox et des combobox quand je remplis tous puis je valide "commandbutton" un message d'erreur : "procédure trop grande" que dois-je faire ?

merci de votre aide !!!!
 

porcinet82

XLDnaute Barbatruc
Re : VBA procédure trop grande

Salut,

Effectivement, ton code est plutot long !!!!
Je viens d'y jeter un oeil et j'ai modifié la partie pour P09. J'aimerai que la teste et que tu me dises si ca fontionne. Si tu peux, essais de continuer les modif si tu y arrives, sinon, il faudrait simplement que tu me dises si tout le reste du code est semblable, j'ai un peu la fleme de tout regarder !!!

Code:
Private Sub CommandButton1_Click()
Dim Valeur As String, i As Integer, cpt As Integer

'Pour P09
With Sheets("P09")
    'les Combo
    cpt = 0
    For i = 2 To 3
        If ComboBox5.Value = "P09" Then
            If .Cells(3, i + cpt).Value = "" Then
                .Cells(3, i + cpt).Value = Controls("ComboBox" & i).Value
            Else
                .Cells(65536, i + cpt).End(xlUp).Offset(1, 0).Value = Controls("ComboBox" & i).Value
            End If
        End If
        cpt = 4
    Next i
    If ComboBox5.Value = "P09" Then
        If .Range("i3") = "" Then
            .Range("i3").Value = ComboBox6.Value
        Else
            .Range("i65536").End(xlUp).Offset(1, 0).Value = ComboBox6.Value
        End If
    End If
    'les Textbox
    cpt = 0
    For i = 2 To 5
        If ComboBox5.Value = "P09" Then
            If .Cells(3, i + 1).Value = "" Then
                .Cells(3, i + 1).Value = Controls("TextBox" & i).Value
            Else
                .Cells(65536, i + 1).End(xlUp).Offset(1, 0).Value = Controls("TextBox" & i).Value
            End If
        End If
    Next i
    For i = 6 To 7
        If ComboBox5.Value = "P09" Then
            If .Cells(3, i - 5 + cpt).Value = "" Then
                .Cells(3, i - 5 + cpt).Value = Controls("TextBox" & i).Value
            Else
                .Cells(65536, i - 5 + cpt).End(xlUp).Offset(1, 0).Value = Controls("TextBox" & i).Value
            End If
        End If
        cpt = 6
    Next i
End With

'Pour P10
'...
End Sub

@+
 
M

Mytå

Guest
Re : VBA procédure trop grande

Salut le forum

Un code valable pour tous les valeurs de la Combobox5, basé sur le code de Porcinet.

Code:
Private Sub CommandButton1_Click()
Dim Valeur As String, i As Integer, cpt As Integer
With Sheets(ComboBox5.Text)
    'les Combo
    cpt = 0
    For i = 2 To 3
            If .Cells(3, i + cpt).Value = "" Then
                .Cells(3, i + cpt).Value = Controls("ComboBox" & i).Value
            Else
                .Cells(65536, i + cpt).End(xlUp).Offset(1, 0).Value = Controls("ComboBox" & i).Value
            End If
        cpt = 4
    Next i
        If .Range("i3") = "" Then
            .Range("i3").Value = ComboBox6.Value
        Else
            .Range("i65536").End(xlUp).Offset(1, 0).Value = ComboBox6.Value
        End If
    'les Textbox
    cpt = 0
    For i = 2 To 5
            If .Cells(3, i + 1).Value = "" Then
                .Cells(3, i + 1).Value = Controls("TextBox" & i).Value
            Else
                .Cells(65536, i + 1).End(xlUp).Offset(1, 0).Value = Controls("TextBox" & i).Value
            End If
    Next i
    For i = 6 To 7
            If .Cells(3, i - 5 + cpt).Value = "" Then
                .Cells(3, i - 5 + cpt).Value = Controls("TextBox" & i).Value
            Else
                .Cells(65536, i - 5 + cpt).End(xlUp).Offset(1, 0).Value = Controls("TextBox" & i).Value
            End If
        cpt = 6
    Next i
End With
End Sub

Mytå
 
Dernière modification par un modérateur:

Discussions similaires

Réponses
17
Affichages
763
  • Résolu(e)
XL pour MAC ISBN
Réponses
37
Affichages
2 K
Réponses
10
Affichages
285

Statistiques des forums

Discussions
312 525
Messages
2 089 329
Membres
104 121
dernier inscrit
bobquad01