Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Clignotement conditionnel d'une cellule (ne fonctionne pas toujours !)

3 réponses
Avatar
JAL
Bonjour , avez-vous une idée sur ce problème

...
Je viens de tester un morceau de VB ci-dessous...



Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Target.Select
If IsNumeric(Target) Then
If ActiveCell.Value > 100 Then Call Clignotement
End If
End Sub

fait passer la couleur de remplissage du blanc
au rouge 300 fois.

Sub Clignotement()
Set plage = ActiveCell
Fond = ActiveCell.Interior.ColorIndex
For i = 1 To 300
plage.Interior.ColorIndex = 2
plage.Interior.ColorIndex = 3
Next i
plage.Interior.ColorIndex = Fond
End Sub

Celui-ci fonctionne mais ,... , pas toujours !

En effet , lorsqu'il est seul dans un fichier "tout neuf" cela va bien ,
sinon , dés que l'on rajoute un autre morceau de prog , il y à blocquage


Le message est alors : "Impossible de définir la propriété colorIndex"





Je ne parviens pas à trouver.... Auriez-vous la solution ?



Cordialement.

3 réponses

Avatar
michdenis
Bonjour Jal,

Copie ce qui suit dans le module feuille où l'action se déroule ...

'------------------------------
Private Sub Worksheet_Change(ByVal Target As Excel.Range)

If IsNumeric(Target) And Target > 100 Then
Call Clignotement(Target)
End If

End Sub
'------------------------------
Sub Clignotement(Rg As Range)

fond = Rg.Interior.ColorIndex
For i = 1 To 300
Rg.Interior.ColorIndex = 3
Application.Wait Now + (TimeValue("00:00:01") / 2)
Rg.Interior.ColorIndex = fond
Next i

End Sub
'------------------------------


Salutations!





"JAL" a écrit dans le message de news: %
Bonjour , avez-vous une idée sur ce problème

...
Je viens de tester un morceau de VB ci-dessous...



Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Target.Select
If IsNumeric(Target) Then
If ActiveCell.Value > 100 Then Call Clignotement
End If
End Sub

fait passer la couleur de remplissage du blanc
au rouge 300 fois.

Sub Clignotement()
Set plage = ActiveCell
Fond = ActiveCell.Interior.ColorIndex
For i = 1 To 300
plage.Interior.ColorIndex = 2
plage.Interior.ColorIndex = 3
Next i
plage.Interior.ColorIndex = Fond
End Sub

Celui-ci fonctionne mais ,... , pas toujours !

En effet , lorsqu'il est seul dans un fichier "tout neuf" cela va bien ,
sinon , dés que l'on rajoute un autre morceau de prog , il y à blocquage


Le message est alors : "Impossible de définir la propriété colorIndex"





Je ne parviens pas à trouver.... Auriez-vous la solution ?



Cordialement.
Avatar
jb
Bonjour,

Worksheet_Change est activé pour tous les changements de la feuille, y
compris les modifs de couleur et les effacements.
Ci dessous, les événnements sont désactivés pendant l'eécution de
la procédure.

http://cjoint.com/?llwK5zqFNi

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Application.EnableEvents = False ' désactive les
événements
If Not Intersect([A1:B10], Target) Is Nothing Then ' champ A1: B10
seulement
If IsNumeric(Target.Value) Then
If Target.Value > 50 Then
beep
'--- clignote
mémoFond = ActiveCell.Interior.ColorIndex
For c = 1 To 100
Target.Interior.ColorIndex = 3
Target.Interior.ColorIndex = mémoFond
Next
'---
End If
End If
End If
Application.EnableEvents = True
End Sub


Ci dessous, le programme est activé seulement lors des saisies dans
les cellules.

Sub auto_open()
ActiveWorkbook.Worksheets("Feuil2").OnEntry = "clignote"
End Sub

Sub clignote()
If Not Intersect([A1:B10], ActiveCell) Is Nothing Then ' champ A1: B10
seulement
If IsNumeric(ActiveCell) Then
If ActiveCell > 50 Then
beep
'--- clignote
mémoFond = ActiveCell.Interior.ColorIndex
For c = 1 To 100
ActiveCell.Interior.ColorIndex = 3
ActiveCell.Interior.ColorIndex = mémoFond
Next
'---
End If
End If
End If
End Sub

Cordialement JB
Avatar
JAL
Merci pour vos réponses rapides et ... complètes...

Bien cordialement.