Private Sub CommandButton2_Click()
' on recupere la ligne, la colonne,le nombre de colonnes
Dim Lig1 As Long
Dim Col1 As String
Dim Nbcol As Byte
Dim Derli As Long
Dim i As Long
' controles données à modifier
If Me.ComboBox1 = "" Then
Call MsgBox("Vous n'avez pas indiqué le :" & Me.Label1.Caption _
& vbCrLf & "" _
, vbExclamation, Application.Name)
Exit Sub
End If
If Me.ListBox1.ListCount = 0 Then
Call MsgBox("Vous n'avez pas sélectionneé des personnes", vbInformation, Application.Name)
Exit Sub
End If
If TextBox1 = "" Then
Call MsgBox("Vous n'avez pas indiqué le :" & Me.Label2.Caption _
& vbCrLf & "" _
, vbExclamation, Application.Name)
Exit Sub
End If
If Nbcol = 3 Then
If TextBox3 = "" Then
Call MsgBox("Vous n'avez pas indiqué le :" & Me.Label3.Caption _
& vbCrLf & "" _
, vbExclamation, Application.Name)
Exit Sub
End If
End If
If TextBox2 = "" Then
Call MsgBox("Vous n'avez pas indiqué le :" & Me.Label4.Caption _
& vbCrLf & "" _
, vbExclamation, Application.Name)
Exit Sub
End If
' on récupère les info
Lig1 = CLng(ComboBox1.List(ComboBox1.ListIndex, 1)) ' numéro de ligne statistiques générales
Col1 = ComboBox1.List(ComboBox1.ListIndex, 2) ' colonne concernant le thème ou type d'action
Nbcol = CByte(ComboBox1.List(ComboBox1.ListIndex, 3)) ' nombre de colonnes si 3 alors date
' on vérifie que le classeur est ouvert
ouverturecla
' pour tous les noms de la listbox
For i = 0 To Me.ListBox1.ListCount - 1 ' index i le premier ayant la valeur 0
With Workbooks(classeur2).Sheets(ListBox1.List(i)) ' on sélectionne la feuille de la personne
Dl1 = .Range(Col1 & "65536").End(xlUp).Row + 1 ' on recherche la ligne à écrire
.Range(Col1 & Derli) = TextBox1 ' on écrit dans les cellules
.Range(Col1 & Derli).Offset(0, 1) = TextBox2
If Nbcol = 3 Then ' si 3 colonnes on inscrit la date
.Range(Col1 & Derli).Offset(0, 2) = TextBox3
End If
End With
Next i ' au suivant
End Sub