View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Otto Moehrbach Otto Moehrbach is offline
external usenet poster
 
Posts: 1,090
Default If Then Else with Exit For

The first If statement, If blnTest = True Then Exit For
is a complete If statement and it stands alone.
You want the "Else" to be a part of that If statement and it can't be. Put
the "Exit For" in the first line on the next line if you want to use "Else".
But the way the code is written, simply remove the "Else" and the "End If"
that goes with the first If statement.
Like this:
For Each c In Range("C:C")
If blnTest = True Then Exit For
If IsNumeric(c) Then
c.EntireColumn.Hidden
blnTest = True
End If
Next c
End Sub
HTH Otto

wrote in message
oups.com...
Hi all

Not sure why my code is failing
Debug comesback highlighted at ELSE

Error is Else without IF

Thanks
-goss

Code :

Option Explicit

Sub TestValue()
Dim c As Range
Dim blnTest As Boolean

blnTest = False

For Each c In Range("C:C")
If blnTest = True Then Exit For
Else
If IsNumeric(c) Then c.EntireColumn.Hidden
blnTest = True
End If
End If
Next c
End Sub