Dim ShCmpt As Object, ligne As Integer, rng As Range
Private Sub UserForm_Initialize()
Set ShCmpt = ThisWorkbook.Sheets("CodeComptes")
Set rng = ShCmpt.Range("A2:D" & ShCmpt.Range("A" & Rows.Count).End(xlUp).Row)
End Sub
Sub operations()
Dim dl As Integer, c As Range, Chaine As String
Chaine = Me.TextBox1.Value
With ShCmpt
dl = .Range("A" & Rows.Count).End(xlUp).Row + 1
'pour ajouter item
If Me.Cb_Valider.Caption = "Ajouter" Then
If Chaine = "" Then MsgBox "Rien à ajouter!": Exit Sub
Set c = rng.Find(What:=Chaine, LookAt:=xlWhole)
If Not c Is Nothing Then
MsgBox Chaine & " existe déjà!"
Exit Sub
Else
.Cells(dl, 1).Value = Actif
.Cells(dl, 2).Value = CDbl(Me.TextBox1.Value)
.Cells(dl, 3).Value = Me.TextBox2.Value
.Cells(dl, 4).Value = CDbl(Me.TextBox3.Value)
.Rows(dl - 1).Copy
.Rows(dl).PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
End If
End Sub