Microsoft 365 Ajouter une condition dans une VBA

Nathan027

XLDnaute Junior
Bonjour à toutes et à tous

Pensez vous qu'il est possible de bloquer ce code quand il est appliqué dans une cellule ou il y a déjà une formule ?

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
temp = Array("X", "")
If Not Application.Intersect(Target, Range("bk11:fl2000")) Is Nothing Then
With Target
p = Application.Match(Target, temp, 0)
If Not IsError(p) Then
If p = UBound(temp) + 1 Then p = 0
Else
p = 0
End If
Target = temp(p)
Cancel = True
End With
End If
End Sub


Merci de votre aide :)
 
Solution
Bonjour à toutes et à tous

Pensez vous qu'il est possible de bloquer ce code quand il est appliqué dans une cellule ou il y a déjà une formule ?

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
temp = Array("X", "")
If Not Application.Intersect(Target, Range("bk11:fl2000")) Is Nothing Then
With Target
p = Application.Match(Target, temp, 0)
If Not IsError(p) Then
If p = UBound(temp) + 1 Then p = 0
Else
p = 0
End If
Target = temp(p)
Cancel = True
End With
End If
End Sub


Merci de votre aide :)
Bonjour,
Essaye comme ceci
VB:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Cancel = True
    If...

Jacky67

XLDnaute Barbatruc
Bonjour à toutes et à tous

Pensez vous qu'il est possible de bloquer ce code quand il est appliqué dans une cellule ou il y a déjà une formule ?

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
temp = Array("X", "")
If Not Application.Intersect(Target, Range("bk11:fl2000")) Is Nothing Then
With Target
p = Application.Match(Target, temp, 0)
If Not IsError(p) Then
If p = UBound(temp) + 1 Then p = 0
Else
p = 0
End If
Target = temp(p)
Cancel = True
End With
End If
End Sub


Merci de votre aide :)
Bonjour,
Essaye comme ceci
VB:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Cancel = True
    If Application.Intersect(Target, Range("bk11:fl2000")) Is Nothing Then Exit Sub
    If Application.IsFormula(Target) Then Exit Sub
    Target.Value = IIf(UCase(Target) = "X", "", "X")
End Sub
 

Discussions similaires

Réponses
2
Affichages
136
Réponses
2
Affichages
149

Statistiques des forums

Discussions
312 206
Messages
2 086 220
Membres
103 158
dernier inscrit
laufin