Commentaire conditionel

Ilino

XLDnaute Barbatruc
Bonsoir Forum
ci rattaché un fichier , j'ai trouvé des diffecultées ( ca bug ) quand je change la valeur de C76 pour la 2eme fois et j'ai ce type de message d'erreur
Erreur d'execution 1004
Erreur definie par l'application ou par l'objet

a ce niveau : [C76].AddComment
A+
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("C76")) Is Nothing Then
If [C76] <> [C75] Then
    [C76].AddComment
    [C76].Comment.Visible = False
    [C76].Comment.Text Text:="La distance de SAR vers SDR est differente de la somme de deux distances SAR_PJ et PJ-SDR"
Else
        [C76].ClearComments
End If
End If
End Sub
 

Ilino

XLDnaute Barbatruc
Re : Commentaire conditionel

Re
merci pour la réponse mais j'ai utilisé
Code:
:
:
:
:
:
:
.

If Not Intersect(Target, Range("C76,c75")) Is Nothing Then
        
        Sheets("feuil3").UnProtect <----- code rajouté

     If Range("c76") <> Range("c75") Then
       If Not (Range("c76").Comment Is Nothing) Then Range("c76").ClearComments
        Range("c76").AddComment
        Range("c76").Comment.Visible = True 'False
        Range("c76").Comment.Text Text:="La distance de SAR vers SDR est differente de la somme de deux distances SAR_PJ et PJ-SDR"
      
      Else
      Range("c76").ClearComments
     
     


      End If
    End If
 Sheets("feuil3").Protect <----- code rajouté

ça fonctionnait mais je veux pas que la feuille3 soit déverrouillée ???
A+
 
Dernière édition:

Ilino

XLDnaute Barbatruc
Re : Commentaire conditionel

Bonsoir Forum
puis je avoir vos commentaire sur ce code
: il est fonctionnelle mais si je clic sur le bouton "Oter la protection" la feuille est déverrouillé, et ça ce n'est pas mon objectif ???
A+
 

Ilino

XLDnaute Barbatruc
Re : Commentaire conditionel

Bonjour Forum
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim n As Byte
Dim Start As Variant
Dim i As Integer
 '---- Afficher un commentaire
If Not Intersect(Target, Range("C76")) Is Nothing Then
   'Sheets("feuil3").Unprotect
    
     If Range("c76") <> Range("c86") + Range("c102") Then
           If Not (Range("c76").Comment Is Nothing) Then Range("c76").ClearComments
        MsgBox "message test"
        Range("C76").AddComment ' <--- ça bug a ce niveau ???
        Range("c76").Comment.Visible = True 'False
        Range("c76").Comment.Text Text:="La distance de SAR vers SDR est differente de la somme de deux distances SAR_PJ et PJ-SDR"
      Else
       
        Range("c76").ClearComments
      End If
    'Sheets("feuil3").Protect
End If

'--- faire clignoter la cellule du commentaire

If [C76] <> 0 And [C86] <> 0 And [C102] <> 0 Then
If Not [C76] = [C86] + [C102] Then
Const Texte As String = ""
For i = 1 To 3
Cells(76, 3).Font.ColorIndex = 2
Cells(76, 3).Interior.ColorIndex = 3
For n = 1 To 10
Start = Timer
Do While Timer < Start + 2 / 100
Loop
If n Mod 5 = 0 Then
Cells(76, 3).Interior.ColorIndex = xlNone
Cells(76, 3).Font.ColorIndex = 1
End If
Next n
Next i
End If
End If
 
'----- Autre commandes
If [H16] <> 1 Then
CommandButton8.Visible = False
Else
CommandButton8.Visible = True
End If

If [H30] <> 1 Then
CommandButton9.Visible = False
Else
CommandButton9.Visible = True
End If

If [H48] <> 1 Then
CommandButton10.Visible = False
Else
CommandButton10.Visible = True
End If

If [H388] <> 1 Then
CommandButton11.Visible = False
Else
CommandButton11.Visible = True
End If

If [C10] = "Technique" Or [C10] = "" Then Range("E10,G10,I10") = ""
If [C24] = "Technique" Or [C24] = "" Then [E24] = ""
If [C42] = "Site Technique" Then [F42] = ""
If [C72] = "" Or [C72] <> "Autre" Then [F72] = ""
If [C318] = "" Or [C318] = "Non" Then [E318] = ""
If [C322] = "" Or [C322] = "Non" Then [F322] = ""
If [C326] = "" Or [C326] = "Non" Then [E326] = ""
If [C334] = "" Or [C334] <> "Autre" Then [F334] = ""
If [C342] = "" Then [E342] = ""
If [C360] = "" Or [C360] <> "Autre ( à définir )" Then [F360] = ""
If [C398] = "" Or [C398] <> "Autre" Then [E398] = ""

If [F402] = "" Or [F402] <> "Autre" Then [I402] = ""
If [F404] = "" Or [F404] <> "Autre" Then [I404] = ""
If [F406] = "" Or [F406] <> "Autre" Then [I406] = ""
If [F408] = "" Or [F408] <> "Autre" Then [I408] = ""
If [F410] = "" Or [F410] <> "Autre" Then [I410] = ""

    
End Sub
ci dessus le code commentaire avec clignement de cellule , j'ai tjr le même bug
message d'errer 1004.
Please
A+
 

Si...

XLDnaute Barbatruc
Re : Commentaire conditionel

salut

Quand tu protèges une feuille, les cellules verrouillées sont interdites de changement.
Tu ne dois pas confondre avec "cellules sélectionnables ou pas" !

Je simplifierais le début ainsi :
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  Dim n As Byte, i As Byte, Start As Double
'---- Afficher un commentaire
 If Not Intersect(Target, [C76]) Is Nothing And Target.Count = 1 Then
    Sheets("feuil3").Unprotect  ‘ici
If Not Target.Comment Is Nothing Then Target.Comment.Delete
   If [C76] <> [C86] + [C102] Then
     Target.AddComment
     Target.Comment.Visible = True
     Target.Comment.Text "La distance de SAR vers SDR est differente de la somme de deux distances SAR_PJ et PJ-SDR"
   End If
  Sheets("feuil3").Protect ‘et là
 End If
  '--- faire clignoter la cellule du commentaire

Mais, Si… d’autres cellules concernées par la suite du code sont verrouillées, tu seras obligé d’enlever à nouveau la protection et pour ne pas te compliquer la tâche tu pourras te contenter de

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  Dim n As Byte, i As Byte, Start As Double
  Sheets("feuil3").Unprotect  ‘ici
 '---- Afficher un commentaire
 … 
   '--- faire clignoter la cellule du commentaire
 ...  
  '----- Autre commandes
  …
  Sheets("feuil3").Protect ‘et là
End Sub
 

Discussions similaires

Réponses
9
Affichages
833

Statistiques des forums

Discussions
314 025
Messages
2 104 767
Membres
109 141
dernier inscrit
nathalie MARTIN