LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
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



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run when exit PH NEWS Excel Worksheet Functions 1 July 18th 06 03:53 PM
how to exit sub xiang Excel Programming 3 December 9th 05 05:46 AM
exit while? Steven Deng Excel Programming 1 November 6th 04 12:14 AM
Exit when its a Mac jose luis Excel Programming 0 September 20th 04 10:47 PM
If a called sub exit, how to the caller exit right away? luvgreen[_4_] Excel Programming 4 February 24th 04 05:06 PM


All times are GMT +1. The time now is 09:52 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"