1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| Option Explicit
Dim myCon()
Private Sub CommandButton2_Click()
Dim R&, i&, N&
'-- Si une textbox est vide, on la comptabilise
For R = 0 To 5
If Me.Controls(myCon(R)).Text = "" Then N = N + 1
Next
'-- Un cherche s'il y a doublon dans la colonne B
For i = 2 To 50000
If Feuil1.Cells(i, 2).Value = Val(TextBox2) Then
MsgBox " >>>>>: Doublon, le code (" & Val(TextBox2) & ") est déja présent sur la feuille pour le nom : " & Feuil1.Cells(i, 3).Text, 16, "Doublon du code"
Exit Sub
Else
End If
Next i
'-- S'il y a au moins un textbox vide on s'arrête
If N <> 0 Then MsgBox "Ajout échoué": GoTo 1
'-- Autres traitements
' ....
'---
1 End Sub
Private Sub CommandButton4_Click()
Unload UserForm1
End Sub
Private Sub UserForm_Activate()
myCon = Array("TextBox1", "TextBox2", "TextBox3", "TextBox4", "TextBox5", "TextBox6")
H_A
End Sub
Private Sub H_A()
Dim RR As Integer, Endrow As Integer
Dim R As Long
ComboBox1.Clear
With Sheets("Feuil1")
Endrow = .Range("A" & .Rows.Count).End(xlUp).Row
For RR = 2 To Endrow
ComboBox1.AddItem .Cells(RR, 1).Value
Next RR
End With
For R = 0 To 5
Me.Controls(myCon(R)) = ""
Next
ComboBox1.Value = ""
CommandButton1.Enabled = True
CommandButton3.Enabled = False
TextBox1.Value = Endrow
TextBox2.SetFocus
End Sub |
Partager