SOLVED

Compile Error: End if without Block if. If Loop Function.

Brass Contributor

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

5 Replies
best response confirmed by ADGToreUp (Brass Contributor)
Solution

@ADGToreUp 

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 Sub

Maybe with these lines of code.

The last "End If" should be an "End Sub". Change that and it should work.

The 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.
Did not think about using Case. Thank you, i will try this.
This worked great. Thank you!
1 best response

Accepted Solutions
best response confirmed by ADGToreUp (Brass Contributor)
Solution

@ADGToreUp 

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 Sub

Maybe with these lines of code.

View solution in original post