utilisation de Private Sub Worksheet_SelectionChange(ByVal Target As Range)
5 réponses
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
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
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
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
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