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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
| Private Sub CommandButton3_Click()
' Nouvel adhérent
Dim Cel As Range
Dim ligne As Long
If Me.ComboBox2.ListIndex = -1 Then
MsgBox "Veuillez choisir la civilité"
Exit Sub
End If
If Trim(Me.TextBox4) = "" Then
MsgBox "Veuillez indiquer un Nom"
Exit Sub
End If
If Trim(Me.TextBox5) = "" Then
MsgBox "Veuillez indiquer un Prénom"
Exit Sub
End If
'Stop
'TextBox7, 9, 10, 11, uniquement en Numerique
If Not IsNumeric(TextBox7) Then
MsgBox "Le code postal doit être renseigné correctement.", vbOKOnly + vbInformation, "Erreur code postal"
TextBox7 = ""
TextBox7.SetFocus
Exit Sub
End If
If Not IsNumeric(TextBox9) Then
MsgBox "Le N° téléphone doit être renseigné correctement.", vbOKOnly + vbInformation, "Erreur N° téléphone"
TextBox9 = ""
TextBox9.SetFocus
Exit Sub
End If
If Not IsNumeric(TextBox10) Then
MsgBox "Le N° Fax doit être renseigné correctement.", vbOKOnly + vbInformation, "Erreur N° Fax"
TextBox10 = ""
TextBox10.SetFocus
Exit Sub
End If
If Not IsNumeric(TextBox11) Then
MsgBox "Le N° Portable doit être renseigné correctement.", vbOKOnly + vbInformation, "Erreur N° Portable"
TextBox11 = ""
TextBox11.SetFocus
Exit Sub
End If
'Stop
With Sheets("Feuil1")
Set Cel = .Columns("C").Find(what:=Me.TextBox4 & " " & Me.TextBox5, LookIn:=xlValues, lookat:=xlWhole)
If Not Cel Is Nothing Then
If MsgBox("Un adhérent ayant ce nom existe déjà : On le modifie ?", vbInformation + vbYesNo, "Modification") <> vbYes Then Exit Sub
ligne = Cel.Row
End If
EnCours = True
If ligne = 0 Then
ligne = .Range("C" & Rows.Count).End(xlUp).Row + 1
Dim ligne As Long
For ligne = 3 To 10
Range("A" & ligne) = "N°" & " " & ligne
Next
'.Range("A" & ligne) = "N°" & " " & Application.max(.Range("A3:A" & ligne)) + 1
'.Range("M" & Ligne) = Application.max(.Range("M3:M" & Ligne)) + 1
End If
.Range("B" & ligne) = Me.ComboBox2
.Range("C" & ligne) = Me.TextBox4 & " " & Me.TextBox5
.Range("D" & ligne) = Me.TextBox4
.Range("E" & ligne) = Me.TextBox5
.Range("F" & ligne) = Me.TextBox6
.Range("G" & ligne) = Me.TextBox7
.Range("H" & ligne) = Me.TextBox8
.Range("I" & ligne) = Me.TextBox9
.Range("J" & ligne) = Me.TextBox10
.Range("K" & ligne) = Me.TextBox11
.Range("L" & ligne) = Me.TextBox14
.Range("L" & ligne).Value = Me.TextBox12 & "@" & Me.TextBox13
Sheets("Feuil1").Hyperlinks.Add Range("L" & ligne), Address:=Cells(3, 12).Value
End With
EnCours = False
Unload Me
UserForm1.Show 0
'Mise en ordre alphabétique sur la feuille
Range("A3:M250").Select
ActiveWorkbook.Worksheets("Feuil1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Feuil1").Sort.SortFields.Add Key:=Range("C3"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Feuil1").Sort
.SetRange Range("A3:M250")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("M1").Select
'Stop
End Sub |
Partager