Petit soucis de combinaison d'une macro sur deux feuilles

INFINITY100

XLDnaute Occasionnel
Bonsoir à tous

Voila je suis face à un petit soucis de combinaison en effet je voudrai appliquer les mêmes procédures de la macro ci-dessous (qui fonctionne parfaitement en feuille1) dans la feuille2 juste en cliquant sur validation

Voici la macro :
Code:
Private Sub CommandButton1_Click()
Dim Ctrl As Control
Dim r As Integer
Dim Derligne As Integer
Dim LigneDebut As Long
Dim x As Integer, L As Integer, nombre_de_colonne As Integer
Dim Ligne As Long, Celluledebut As Integer, Cellulefin As Integer
 
With Worksheets("feuil1")
LigneDebut = 12
Derligne = .Range("A" & Cells.Rows.Count).End(xlUp).Row + 1
Ligne = Derligne
Celluledebut = 3: Cellulefin = 7
Range(Cells(Ligne, Celluledebut), Cells(Ligne, Cellulefin)).Merge
For Each Ctrl In UserForm1.Controls
r = Val(Ctrl.Tag)
If r > 0 Then Feuil1.Cells(Derligne, r) = Ctrl
nombre_de_colonne = 2
  For x = 2 To nombre_de_colonne
    L = Cells(Rows.Count, 1).End(xlUp).Row
    Cells(L + 1, x).Formula = "=SUM(" & Cells(12, x).Address & ":" & Cells(L, x).Address & ")"
             Next
         Next
   End With
   TextBox1 = ""
   Unload Me
End Sub

voici mon classeur pour être plus claire

Merci

Cordialment
 

Pièces jointes

  • Classeur.xlsm
    30.8 KB · Affichages: 28
  • Classeur.xlsm
    30.8 KB · Affichages: 36
  • Classeur.xlsm
    30.8 KB · Affichages: 33
C

Compte Supprimé 979

Guest
Re : Petit soucis de combinaison d'une macro sur deux feuilles

Bonjour Infinity100

Voici le code remanié ;)
Code:
Private Sub CommandButton1_Click()
  Dim Ctrl As Control  Dim r As Integer
  Dim Derligne As Integer
  Dim LigneDebut As Long
  Dim x As Integer, L As Integer, nombre_de_colonne As Integer
  Dim Ligne As Long, Celluledebut As Integer, Cellulefin As Integer
  Dim Ind As Integer, sTabF() As String


  ' Définir le tableau des feuilles à modifier
  sTabF = Split("Feuil1,Feuil2", ",")
  ' Pour chaque feuille
  For Ind = 0 To UBound(sTabF)
    ' Avec la feuille "Ind"
    With Worksheets(sTabF(Ind))
      LigneDebut = 12
      Derligne = .Range("A" & Cells.Rows.Count).End(xlUp).Row + 1
      Ligne = Derligne
      Celluledebut = 3: Cellulefin = 7
      .Range(.Cells(Ligne, Celluledebut), .Cells(Ligne, Cellulefin)).Merge
      For Each Ctrl In UserForm1.Controls
        r = Val(Ctrl.Tag)
        If r > 0 Then .Cells(Derligne, r) = Ctrl
      Next
      ' Mettre le total du tableau
      nombre_de_colonne = 2
      L = .Cells(Rows.Count, 1).End(xlUp).Row
      For x = 2 To nombre_de_colonne
        .Cells(L + 1, x).Formula = "=SUM(" & .Cells(12, x).Address & ":" & .Cells(L, x).Address & ")"
      Next
    End With
  Next Ind
  TextBox1 = ""
  Unload Me
End Sub

Cordialement
 

Membres actuellement en ligne

Aucun membre en ligne actuellement.

Statistiques des forums

Discussions
312 084
Messages
2 085 192
Membres
102 809
dernier inscrit
Sandrine83