Ceci est une page optimisée pour les mobiles. Cliquez sur ce texte pour afficher la vraie page.

Enregistrement sur 2 feuilles

  • Initiateur de la discussion Initiateur de la discussion apdf1
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

apdf1

XLDnaute Impliqué
Bonjour,

Comment peut on enregistrer sur 2 feuilles en même temps dans le même classeur.

Voici mon code

Code:
Private Sub CommandButton2_Click()
    If ComboBox1.ListIndex > -1 Then
        With Sheets(ComboBox1.Text)
            .Range("B5:L5").Insert shift:=xlDown, CopyOrigin:=xlFormatFromRightOrBelow
        
            .Cells(5, 4) = TextBox1.Value: TextBox1 = ""    ' Nom
            .Cells(5, 5) = TextBox2.Value: TextBox2 = ""    ' Prénom
            .Cells(5, 6) = TextBox3.Value: TextBox3 = ""    ' Adresse
            .Cells(5, 8) = TextBox4.Value: TextBox4 = ""    ' Ville
            .Cells(5, 7) = TextBox5.Value: TextBox5 = ""    ' C.P
            .Cells(5, 9) = TextBox6.Value: TextBox6 = ""    ' Tel
            .Cells(5, 2) = TextBox7.Value: TextBox7 = ""    ' Date
            .Cells(5, 3) = TextBox11.Value: TextBox11 = ""  ' N° Cde
            .Cells(5, 10) = TextBox8.Value: TextBox8 = ""   ' Montant
            .Cells(5, 11) = TextBox9.Value: TextBox9 = ""   ' Frais
            .Cells(5, 12) = TextBox10.Value: TextBox10 = "" ' T.T.C
        End With
        ComboBox1.ListIndex = -1
    Else
        MsgBox "Choisir un 'Tranmetteur' !"
    End If
End Sub


Merci d'avance

Max
 
Re : Enregistrement sur 2 feuilles

Bonjour,
peut être comme ceci, nom de la 2ème feuille à adapter, puisque nous ne savons pas ou tu la prends...
Code:
Private Sub CommandButton2_Click()
Dim t() As Variant, i As Byte
    If ComboBox1.ListIndex > -1 Then
        t = Array(ComboBox1.Text, "NomFeuil2")
        For i = 0 To 1
            With Sheets(t(i))
                .Range("B5:L5").Insert shift:=xlDown, CopyOrigin:=xlFormatFromRightOrBelow
                .Cells(5, 4) = TextBox1.Value: TextBox1 = ""    ' Nom
                .Cells(5, 5) = TextBox2.Value: TextBox2 = ""    ' Prénom
                .Cells(5, 6) = TextBox3.Value: TextBox3 = ""    ' Adresse
                .Cells(5, 8) = TextBox4.Value: TextBox4 = ""    ' Ville
                .Cells(5, 7) = TextBox5.Value: TextBox5 = ""    ' C.P
                .Cells(5, 9) = TextBox6.Value: TextBox6 = ""    ' Tel
                .Cells(5, 2) = TextBox7.Value: TextBox7 = ""    ' Date
                .Cells(5, 3) = TextBox11.Value: TextBox11 = ""  ' N° Cde
                .Cells(5, 10) = TextBox8.Value: TextBox8 = ""   ' Montant
                .Cells(5, 11) = TextBox9.Value: TextBox9 = ""   ' Frais
                .Cells(5, 12) = TextBox10.Value: TextBox10 = "" ' T.T.C
            End With
        Next i
        ComboBox1.ListIndex = -1
    Else
        MsgBox "Choisir un 'Tranmetteur' !"
    End If
End Sub
bonne journée
@+
 
Re : Enregistrement sur 2 feuilles

Re,

il faut bien sur remettre à blanc les textbox APRES la boucle...

Code:
Private Sub CommandButton2_Click()
Dim t() As Variant, i As Byte
    If ComboBox1.ListIndex > -1 Then
        t = Array(ComboBox1.Text, "NomFeuil2")
        For i = 0 To 1
            With Sheets(t(i))
                .Range("B5:L5").Insert shift:=xlDown, CopyOrigin:=xlFormatFromRightOrBelow
                .Cells(5, 4) = TextBox1.Value: TextBox1 = ""    ' Nom
                .Cells(5, 5) = TextBox2.Value: TextBox2 = ""    ' Prénom
                .Cells(5, 6) = TextBox3.Value: TextBox3 = ""    ' Adresse
                .Cells(5, 8) = TextBox4.Value: TextBox4 = ""    ' Ville
                .Cells(5, 7) = TextBox5.Value: TextBox5 = ""    ' C.P
                .Cells(5, 9) = TextBox6.Value: TextBox6 = ""    ' Tel
                .Cells(5, 2) = TextBox7.Value: TextBox7 = ""    ' Date
                .Cells(5, 3) = TextBox11.Value: TextBox11 = ""  ' N° Cde
                .Cells(5, 10) = TextBox8.Value: TextBox8 = ""   ' Montant
                .Cells(5, 11) = TextBox9.Value: TextBox9 = ""   ' Frais
                .Cells(5, 12) = TextBox10.Value: TextBox10 = "" ' T.T.C
            End With
        Next i
        TextBox1 = ""    ' Nom
        TextBox2 = ""    ' Prénom
        TextBox3 = ""    ' Adresse
        TextBox4 = ""    ' Ville
        TextBox5 = ""    ' C.P
        TextBox6 = ""    ' Tel
        TextBox7 = ""    ' Date
        TextBox11 = ""  ' N° Cde
        TextBox8 = ""   ' Montant
        TextBox9 = ""   ' Frais
        TextBox10 = "" ' T.T.C
        ComboBox1.ListIndex = -1
    Else
        MsgBox "Choisir un 'Tranmetteur' !"
    End If
End Sub
 
Re : Enregistrement sur 2 feuilles

Bonjour apdf1, Pierrot93,

Il l'a dit, mais il l'a fait qu'à moitié ^^ : Il faut bien sur remettre à blanc les champs des textbox après la boucle (et donc pas dedans !). Petit oubli réparé ici :
Code:
Private Sub CommandButton2_Click()
Dim t() As Variant, i As Byte
    If ComboBox1.ListIndex > -1 Then
        t = Array(ComboBox1.Text, "NomFeuil2")
        For i = 0 To 1
            With Sheets(t(i))
                .Range("B5:L5").Insert shift:=xlDown, CopyOrigin:=xlFormatFromRightOrBelow
                .Cells(5, 4) = TextBox1.Value
                .Cells(5, 5) = TextBox2.Value
                .Cells(5, 6) = TextBox3.Value
                .Cells(5, 8) = TextBox4.Value
                .Cells(5, 7) = TextBox5.Value
                .Cells(5, 9) = TextBox6.Value
                .Cells(5, 2) = TextBox7.Value
                .Cells(5, 3) = TextBox11.Value
                .Cells(5, 10) = TextBox8.Value
                .Cells(5, 11) = TextBox9.Value
                .Cells(5, 12) = TextBox10.Value
            End With
        Next i
        TextBox1 = ""    ' Nom
        TextBox2 = ""    ' Prénom
        TextBox3 = ""    ' Adresse
        TextBox4 = ""    ' Ville
        TextBox5 = ""    ' C.P
        TextBox6 = ""    ' Tel
        TextBox7 = ""    ' Date
        TextBox11 = ""  ' N° Cde
        TextBox8 = ""   ' Montant
        TextBox9 = ""   ' Frais
        TextBox10 = "" ' T.T.C
        ComboBox1.ListIndex = -1
    Else
        MsgBox "Choisir un 'Tranmetteur' !"
    End If
End Sub
 
Re : Enregistrement sur 2 feuilles

Re,

bon je reposte à nouveau, mais impossible de modifier ce message.....
Code:
Private Sub CommandButton2_Click()
Dim t() As Variant, i As Byte
    If ComboBox1.ListIndex > -1 Then
        t = Array(ComboBox1.Text, "NomFeuil2")
        For i = 0 To 1
            With Sheets(t(i))
                .Range("B5:L5").Insert shift:=xlDown, CopyOrigin:=xlFormatFromRightOrBelow
                .Cells(5, 4) = TextBox1.Value
                .Cells(5, 5) = TextBox2.Value
                .Cells(5, 6) = TextBox3.Value
                .Cells(5, 8) = TextBox4.Value
                .Cells(5, 7) = TextBox5.Value
                .Cells(5, 9) = TextBox6.Value
                .Cells(5, 2) = TextBox7.Value
                .Cells(5, 3) = TextBox11.Value
                .Cells(5, 10) = TextBox8.Value
                .Cells(5, 11) = TextBox9.Value
                .Cells(5, 12) = TextBox10.Value
            End With
        Next i
        For i = 1 To 12
              Me.Controls("Textbox" & i) = ""
        Next i
ComboBox1.ListIndex = -1
    Else
        MsgBox "Choisir un 'Tranmetteur' !"
    End If
End Sub

Edité
 
Dernière édition:
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
2
Affichages
589
Réponses
3
Affichages
922
B
  • Question Question
Réponses
3
Affichages
1 K
Réponses
7
Affichages
1 K
Les cookies sont requis pour utiliser ce site. Vous devez les accepter pour continuer à utiliser le site. En savoir plus…