View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
[email protected] goss9394@yahoo.com is offline
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