Userform multi TextBox

denisbouchard

XLDnaute Junior
Bonjour à tout le forum,

Je voudrais créer un Userform qui à l'aide de plusieurs TextBox (entre 1 et 20) reprenne des infos de certaines cases sur un feuille pour les recopier sur une autre. Pour un TextBox je sais faire, mais je voudrais le faire sans recopier 20 fois la même macro. J'ai essayé plusieurs choses avec "for each", mais rien ne fonctionne. Quelqu'un peut-il m'aider?
Merci par avance.
Denis
 

Pièces jointes

  • Classeur1.xlsm
    19.5 KB · Affichages: 62
  • Classeur1.xlsm
    19.5 KB · Affichages: 68
  • Classeur1.xlsm
    19.5 KB · Affichages: 64

CHALET53

XLDnaute Barbatruc
Re : Userform multi TextBox

Bonjour,

Remplace ton code par celui-ci (et avec contrôle des doublons)

Private Sub Button_OK_Click()
Dim nom As String
Dim i As Integer, j As Integer, k As Integer
Dim lig(100) As Integer
Dim derligne As Integer
Dim ctrl As Control

Sheets("Feuil1").Activate

For Each ctrl In UserForm1.Controls
If TypeOf ctrl Is MSForms.TextBox Then
'Stop
If ctrl.Value <> "" Then
'Stop
i = i + 1
lig(i) = ctrl.Value
End If
End If
Next

For k = 1 To i
For j = k + 1 To i
If lig(k) = lig(j) Then MsgBox ("Deux fois la valeur " & lig(k)): Exit Sub
Next j
Next k

For Each ctrl In Controls
'If CTRL = ComboBox1 Then GoTo label98
If TypeOf ctrl Is MSForms.TextBox Then
'Stop
[A11].Activate
nom = ctrl.Name
If ctrl.Value = "" Then GoTo suite
Chiffre = ctrl.Value
Do While (ActiveCell.Value <> Chiffre)
rang = rang + 1
ActiveCell.Offset(1, 0).Activate
If rang >= 100 Then
Exit Sub
End If
Loop
' Stop
derligne = Sheets("Feuil2").Range("A65536").End(xlUp).Row + 1
cible = ActiveCell.Row
Range(Cells(cible, 2), Cells(cible, 3)).Copy Destination:=IIf(Sheets("Feuil2").Range("A1") = "", _
Sheets("Feuil2").Range("A1"), Sheets("Feuil2").Range("A" & derligne))
' Unload UserForm1
' Sheets("Feuil2").Select
End If
suite:
Next
End Sub

a+
 
Dernière édition:

CHALET53

XLDnaute Barbatruc
Re : Userform multi TextBox

A priori, rajoute : rang=0 après If TypeOf ctrl Is MSForms.TextBox Then

For Each ctrl In Controls
'If CTRL = ComboBox1 Then GoTo label98
If TypeOf ctrl Is MSForms.TextBox Then
'Stop
rang=0
[A11].Activate
nom = ctrl.Name
If ctrl.Value = "" Then GoTo suite
Chiffre = ctrl.Value
Do While (ActiveCell.Value <> Chiffre)
 

Discussions similaires

Réponses
17
Affichages
721

Statistiques des forums

Discussions
312 378
Messages
2 087 760
Membres
103 661
dernier inscrit
fcleves