Else without If

JazzzyJo

Board Regular
Joined
Jul 12, 2011
Messages
60
Hello All

Why do I get a Else Without If error in the below code?
I'm probably blind but I looked at it several time and I dont get it.

Thank you

p.s. The color are all the same. Just did not set them up yet.

Dim btn As Shape
Dim arrayFDE() As String
Dim searchCat As Long
arrayFDE = Split(Range("L" & activeRow).Value, vbLf)
For k = 0 To UBound(arrayFDE)
Set btn = Shapes("Button" & k + 1)
btn.TextFrame.Characters.Text = arrayFDE(k)

searchCat = InStr(1, arrayFDE(k), "(Warning)", vbTextCompare)
If searchCat > 0 Then
With btn.TextFrame.Characters.Font
.Color = RGB(255, 83, 83)
Else
searchCat = InStr(1, arrayFDE(k), "(Status)", vbTextCompare)
If searchCat > 0 Then
With btn.TextFrame.Characters.Font
.Color = RGB(255, 83, 83)
Else
searchCat = InStr(1, arrayFDE(k), "(Advisory)", vbTextCompare)
If searchCat > 0 Then
With btn.TextFrame.Characters.Font
.Color = RGB(255, 83, 83)
Else
searchCat = InStr(1, arrayFDE(k), "(Status)", vbTextCompare)
If searchCat > 0 Then
With btn.TextFrame.Characters.Font
.Color = RGB(255, 83, 83)
Else
searchCat = InStr(1, arrayFDE(k), "(Info)", vbTextCompare)
If searchCat > 0 Then
With btn.TextFrame.Characters.Font
.Color = RGB(255, 83, 83)
End If
End If
End If
End If
End If

Next k
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
When you nest a WITH clause within an IF clause, you MUST close out of the WITH before going to the else, i.e.
this is an invalid structure:
VBA Code:
If...
    With ....
Else ...
    End With
End If
This is a valid strucutre:
VBA Code:
If...
    With ....
    End With
Else...
End If
 
Upvote 0

Forum statistics

Threads
1,215,497
Messages
6,125,158
Members
449,208
Latest member
emmac

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top