Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default If Then Else with Exit For


K Dales wrote:
First, you forgot an End If:
For Each c In Range("C:C")
If blnTest = True Then
Exit For
Else
If IsNumeric(c) Then
c.EntireColumn.Hidden = True
blnTest = True
End If
End If
Next c

Tip: by indenting (as you did) you can scan up and down the lines of code
and make sure every loop and multi-line statement has all the required parts
in it. I could see that the inner If had an End If, but the outer one only
had If.. and Else. Since it had not closed properly, when the debugger hit
the Next statement, it could not match it with the For. You cannot have a
loop that starts outside of an if statement and ends inside it.

The other question:
Intellisense will only give you options when there is a predefined list of
options (in the background, this is when the Excel object code contains an
enumerated list of constant values - like using the Enum statement). If the
options are simply common constants like true or false or numerical values
you can choose freely, you won't get any help of this sort.

--
- K Dales


" wrote:

Thanks -

Now comesback Next w/o For error.

A few other questions
When I type EntireColumn. Intellisense pops up a listbox of properties
and methods
When I type pastespecial I receive some xlxxxxxxxx options
But other times I have to know that I have to type Hidden = True or
False
Why is this?

Thanks
-goss

Revised 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 = True
blnTest = True
End If
Next c
End Sub



Thanks
I had the second End If originally, but removed it based on Otto's
reply
But at that time the code was written

If blnTest = True Then Exit For
(Perhaps this synax terminates and the End If is not necessary?)

Instead of

If blnTest = True Then
Exit For
Else
If IsNumeric.......

Thanks
-goss

Reply
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 02:04 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"