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

utilisation de Private Sub Worksheet_SelectionChange(ByVal Target As Range)

5 réponses
Avatar
JP
Bonjour,

Dans ce type de code, comment sortir de la boucle infernale. En fin de bouc=
le, le Range(Ad).select d=E9clenche =E0 nouveau la macro.

Merci JP

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim l As Integer
Dim Ad As Variant
'-------
If Not Intersect(Target, Range("D25:I226")) Is Nothing Then
Ad =3D ActiveCell.Address
l =3D ActiveCell.Row
'Application.ScreenUpdating =3D False
Range("C25:C226").Select
Selection.Font.ColorIndex =3D 2
Cells(l, 3).Select
Selection.Font.Color =3D 0
End If
Range(Ad).Select
End Sub

5 réponses

Avatar
DanielCo
Bonjour,
Tu peux mettre ça :
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim l As Integer
Dim Ad As Variant
'-------
Application.EnableEvents = False
If Not Intersect(Target, Range("D25:I226")) Is Nothing Then
Ad = ActiveCell.Address
l = ActiveCell.Row
'Application.ScreenUpdating = False
Range("C25:C226").Select
Selection.Font.ColorIndex = 2
Cells(l, 3).Select
Selection.Font.Color = 0
End If
Range(Ad).Select
Application.EnableEvents = True
End Sub
Toutefois, si la condition :
If Not Intersect(Target, Range("D25:I226")) Is Nothing Then
n'est pas remplie, Ad n'est pas défini, ce qui doit provoquer une
erreur. Peut-être comme ça :
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim l As Integer
Dim Ad As Variant
'-------
If Not Intersect(Target, Range("D25:I226")) Is Nothing Then
Ad = ActiveCell.Address
l = ActiveCell.Row
'Application.ScreenUpdating = False
Range("C25:C226").Font.ColorIndex = 2
Cells(l, 3).Font.Color = 0
End If
End Sub
Daniel


Bonjour,

Dans ce type de code, comment sortir de la boucle infernale. En fin de
boucle, le Range(Ad).select déclenche à nouveau la macro.

Merci JP

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim l As Integer
Dim Ad As Variant
'-------
If Not Intersect(Target, Range("D25:I226")) Is Nothing Then
Ad = ActiveCell.Address
l = ActiveCell.Row
'Application.ScreenUpdating = False
Range("C25:C226").Select
Selection.Font.ColorIndex = 2
Cells(l, 3).Select
Selection.Font.Color = 0
End If
Range(Ad).Select
End Sub
Avatar
JP
Merci Jacky, ça fonctionne.

JP
Avatar
Jacky
Merci Jacky, ça fonctionne.











J'ai rien fait......Moi!
;o))
--
Salutations
JJ


"JP" a écrit dans le message de news:

Merci Jacky, ça fonctionne.

JP
Avatar
JP
Ben, si car il fallait supprimer les .select

JP
Avatar
JP
A zut alors, décidément il faut que je change de lunette!
Désolé Daniel :-o)

JP