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
| Private Sub CheckDoublon_Click()
Dim emptyRow As Long
Dim suite As Long
Dim MyRange As Range
Dim Init As Boolean
'Make Sheet3 Active
Sheets(2).Activate
Dim L As Long
Set MyRange = Sheets(2).UsedRange
For L = 2 To MyRange.Rows.Count
Highlander Init, MyRange(L, 1)
Next
'Determine EmptyRow
If Highlander(Init, TextBox1.Value) = False Then
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
'Export Data to worksheet
Cells(emptyRow, 1).Value = TextBox1.Value
Cells(emptyRow, 2).Value = TextBox2.Value
Else
MsgBox "Le N° " & TextBox1.Value & " exite déjà", vbExclamation
End If
If MsgBox("voulez-vous saisir un autre produit ?", vbYesNo + vbQuestion)= vbYes then
Sheets(2).Activate
Else
Unload UserForm1
End If
End Sub
Private Sub Fermer_Click()
Unload UserForm1
End Sub
Function Highlander(Init As Boolean, ParamArray Plage()) As Boolean
'..................................................
'La méthode Highlander, il ne peut en rester qu'un.
'Retourne True si doublon.
'..................................................
Static CollectDoublon As Collection
Dim T As String
Dim PlageIndex As Long
Dim myPlage As Range
Dim Col As Integer
Dim Tableau
If Init = False Then
Init = True
Set CollectDoublon = Nothing
Set CollectDoublon = New Collection
End If
T = "T"
For PlageIndex = 0 To UBound(Plage)
If TypeName(Plage(PlageIndex)) = "Range" Then
Set myPlage = Plage(PlageIndex)
For Col = 1 To myPlage.Columns.Count
T = T & "_" & Trim("" & myPlage(1, Col))
Next
Else
If TypeName(Plage(PlageIndex)) = "Variant()" Then
Tableau = Plage(PlageIndex)
Else
If TypeName(Plage(PlageIndex)) Like "*()" Then
Tableau = Plage(PlageIndex)
Else
Tableau = Split(Plage(PlageIndex) & ";", ";")
End If
End If
For Col = 0 To UBound(Tableau)
If Trim("" & Tableau(Col)) <> "" Then T = T & "_" & Trim("" & Tableau(Col))
Next
End If
Next
On Error Resume Next
CollectDoublon.Add T, T
If Err <> 0 Then Highlander = True
On Error GoTo 0
End Function |
Partager