http://www.excel-downloads.com/forum/234625-resolu-msgbox-dans-une-boucle-selon-countif.html
If .Comment Is Nothing Then .AddComment
C'est bien pour çà que je m'en viens sur ce post...Tu es sûr de ce que tu fais dans ton code ?
C'est bien pour ça que je te propose de ne l'ajouter que s'il n'y en a pas, sinon non :Car je ne peux pas faire addcomment sur une cellule qui en a déjà un.
If .Comment Is Nothing Then .AddComment
If cel Is Nothing Then
With cel
If cel.Comment Is Nothing Then
With cel
On Error Resume Next
y = IsError(Range(Plage(ActiveCell)).Find(ListBox2.List(i) & d, , , xlWhole).Address)
If y <> "" Then
Set cel = Range(Plage(ActiveCell)).Find(ListBox2.List(i) & d, , , xlWhole)
Lg = PremiereLigne(ActiveCell)
Col = cel.Column
MsgBox ListBox2.List(i) & vbCr & "doublon en " & cel.Address _
& vbLf & "Animateur : " & Cells(Lg - 3, Col).Text _
& vbLf & "Lieu : " & Cells(Lg - 2, Col).Text, vbInformation, "Attention !"
End If
On Error GoTo 0
y = IsError(Range(Plage(ActiveCell)).Find(ListBox2.List(i) & d, , , xlWhole).Address)
If y <> "" Then
Set cel = Range(Plage(ActiveCell)).Find(ListBox2.List(i) & d, , , xlWhole)
if cel is nothing then
'...
else
'...
endif
Private Sub CommandButton_done_Click()
Dim i, counter As Integer
Dim y, d As String
Dim Col, lg0, col0 As Integer
Dim cel As Range
lg0 = PremiereLigne(ActiveCell)
col0 = ActiveCell.Column
Application.Calculation = xlCalculationManual
If CheckBox1 = True Then
max = 15
For i = 0 To ListBox1.ListCount - 1
ActiveCell.Offset(i, 0) = ListBox1.List(i)
If i = max Then Exit For
Next i
End If
If CheckBox2 = True Then
d = " 0,5"
End If
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then ListBox2.AddItem ListBox1.List(i)
Next i
For i = 0 To ListBox2.ListCount - 1
If ListBox2.Selected(i - counter) Then
ListBox2.RemoveItem (i - counter)
counter = counter + 1
End If
Next i
For i = 0 To ListBox2.ListCount - 1
On Error Resume Next
y = IsError(Range(Plage(ActiveCell)).Find(ListBox2.List(i) & d, , , xlWhole).Address)
On Error GoTo 0
If y = False Then
Set cel = Range(Plage(ActiveCell)).Find(ListBox2.List(i) & d, , , xlWhole)
Lg = PremiereLigne(ActiveCell)
Col = cel.Column
MsgBox ListBox2.List(i) & vbCr & "doublon en " & cel.Address _
& vbLf & "Animateur : " & Cells(Lg - 3, Col).Text _
& vbLf & "Lieu : " & Cells(Lg - 2, Col).Text, vbInformation, "Attention !"
If cel.Comment Is Nothing Then
With cel
.AddComment
.Comment.Visible = True
.Comment.Text Text:="ATTENTION DOUBLON !" _
& Chr(10) & cel.Value _
& Chr(10) & "Avec " & Cells(lg0 - 3, col0).Text _
& Chr(10) & "à " & Cells(lg0 - 2, col0).Text _
& Chr(10) & "cellule " & ActiveCell.Offset(i, 0).Address
End With
With ActiveCell.Offset(i, 0)
.Value = ListBox2.List(i) & d
.AddComment
.Comment.Visible = True
.Comment.Text Text:="ATTENTION DOUBLON !" _
& Chr(10) & ListBox2.List(i) _
& Chr(10) & "Animateur : " & Cells(Lg - 3, Col).Text _
& Chr(10) & "Lieu : " & Cells(Lg - 2, Col).Text
End With
Else
MsgBox "TRIPLON..." & Chr(10) & "En demi-séance c'est possible, sinon vérifier les attributions.", vbExclamation, "ATTENTION" 'il y a déjà un commentaire dans la cellule
With ActiveCell.Offset(i, 0) 'commentaire dans la nouvelle cellule
.Value = ListBox2.List(i) & d
'.Interior.Color = 255
.AddComment
.Comment.Visible = True
.Comment.Text Text:="ATTENTION TRIPLON !" _
& Chr(10) & "en " & cel _
& Chr(10) & "Animateur : " & Cells(Lg - 3, Col).Text _
& Chr(10) & "Lieu : " & Cells(Lg - 2, Col).Text
End With
End If
End If
ActiveCell.Offset(i, 0) = ListBox2.List(i) & d
Next i
Call tailleZoneCommentaire
Call modificationCommentaires
Application.Calculation = xlCalculationAutomatic
Unload UserForm1
'ActiveCell.Offset(0, 1).Select
End Sub
Dim pl as Range, c as Range
For i = 0 To ListBox2.ListCount - 1
Set pl = Range(Plage(ActiveCell))
If Not pl Is Nothing Then
Set c = pl.Find(ListBox2.List(i) & d, , , xlWhole)
If c Is Nothing Then
'MsgBox "ok"
Else
If ActiveCell.Comment Is Nothing Then ActiveCell.AddComment
With ActiveCell.Comment
.Visible = True
.Text Text:="ATTENTION DOUBLON avec " & c.Address
End With
MsgBox "Doublon"
End If
End If
Next i
For i = 0 To ListBox2.ListCount - 1
Set pl = Range(Plage(ActiveCell))
If Not pl Is Nothing Then
Set c = pl.Find(ListBox2.List(i) & d, , , xlWhole)
If c Is Nothing Then
'MsgBox "ok"
Else
Lg = PremiereLigne(c)
Col = c.Column
If ActiveCell.Offset(i, 0).Comment Is Nothing Then ActiveCell.Offset(i, 0).AddComment
With ActiveCell.Offset(i, 0).Comment
.Visible = True
.Text Text:="ATTENTION DOUBLON !" _
& Chr(10) & c _
& Chr(10) & "Animateur : " & Cells(Lg - 3, Col).Text _
& Chr(10) & "Lieu : " & Cells(Lg - 2, Col).Text
End With
lg0 = PremiereLigne(ActiveCell)
col0 = ActiveCell.Column
If c.Comment Is Nothing Then c.AddComment
With c.Comment
.Visible = True
.Text Text:="ATTENTION DOUBLON !" _
& Chr(10) & c _
& Chr(10) & "Animateur : " & Cells(lg0 - 3, col0).Text _
& Chr(10) & "Lieu : " & Cells(lg0 - 2, col0).Text
End With
MsgBox c & vbCr & "doublon en " & c.Address _
& vbLf & "Animateur : " & Cells(Lg - 3, Col).Text _
& vbLf & "Lieu : " & Cells(Lg - 2, Col).Text, vbInformation, "Attention !"
End If
End If
ActiveCell.Offset(i, 0) = ListBox2.List(i) & d
Next i
Logiquement si c'est la 3ème fois que tu rentres un nom, les deux premières cellules ont déjà leur commentaire puisque le doublon a été détecté.tant pis pour les triplons