Forum Discussion
Compile Error: End if without Block if. If Loop Function.
Hello Everybody,
I have a loop function while using the "Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)" function. I have a spread sheet that loops through wing dings, with conditional formats, so that user can just double click and change the status of items at ease. Everthing worked great, but then i needed to add one more status to the loop and it broke. The error i get in the code below is a Compile Error, stating that "End If without block IF." All help is greatly appreciated, thank you for your time.
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("F11:L43")) Is Nothing Then
If Target.Value = "/" Then Target.Value = "$"
ActiveSheet.Range("A22").Select
Exit Sub
End If
If Target.Value = "O" Then Target.Value = "/"
If Target.Value = "P" Then Target.Value = "O"
If Target.Value = "$" Then Target.Value = "P"
If Target.Value = Empty Then Target.Value = "/"
ActiveSheet.Range("A22").Select
End If
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) If Not Intersect(Target, Range("F11:L43")) Is Nothing Then Select Case Target.Value Case Is = "/" Target.Value = "$" Case Is = "O" Target.Value = "/" Case Is = "P" Target.Value = "O" Case Is = "$" Target.Value = "P" Case Is = Empty Target.Value = "/" End Select ActiveSheet.Range("A22").Select End If End SubMaybe with these lines of code.
5 Replies
- Rsartori76Brass Contributor
The last "End If" should be an "End Sub". Change that and it should work.
- ADGToreUpBrass ContributorThe issue with that, is i have other ranges that i am doing other loops on for the double click, with different value in those ranges, so i cannot end the sub right at that point.
- OliverScheurichGold Contributor
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) If Not Intersect(Target, Range("F11:L43")) Is Nothing Then Select Case Target.Value Case Is = "/" Target.Value = "$" Case Is = "O" Target.Value = "/" Case Is = "P" Target.Value = "O" Case Is = "$" Target.Value = "P" Case Is = Empty Target.Value = "/" End Select ActiveSheet.Range("A22").Select End If End SubMaybe with these lines of code.