Type of variable

J

J@Y

Code:

For each C in Range1
Call FindMe(C)
Next For

Sub FindMe(Cel as Range)

....

End Sub

Apparently, the C in the For statement won't get passed on to the FindMe Sub
as a Range variable. I have to use Sub FindMe(Cel) without the "as Range" for
this to work. Why is the C not a Range variable? I can do C.address and it
returns a Cell address.
 
S

Sandusky

J@Y said:
Code:

For each C in Range1
Call FindMe(C)
Next For

Sub FindMe(Cel as Range)

...

End Sub

Apparently, the C in the For statement won't get passed on to the FindMe
Sub
as a Range variable. I have to use Sub FindMe(Cel) without the "as Range"
for
this to work. Why is the C not a Range variable? I can do C.address and it
returns a Cell address.

Windows XP Pro SP2
Excel 2002 SP3

This worked for me:

Sub test2()

Dim c As Range, range1 As Range

Set range1 = Range("A1:A10")

For Each c In range1
Call FindMe(c)
Next c

End Sub

Sub FindMe(Cel As Range)

MsgBox Cel.Address

End Sub

====================================================

I noticed in your code you had "Next For", which I assume is a typo.
Otherwise everything looks fine. You did declare c as a range variable,
right?

-gk-
 
J

J@Y

Ok I didn't define C explicitly. I guess it gets dim ed as a Variant in my
case. Thanks.
 
J

Jim Thomlinson

What you have there looks fine to me assuming that everything is declared as
I would expect. Make sure to explicitly declare all of your variables...

Sub This()
Dim C as Range
Dim Range1 as Range

Set Range1 = range("A1:A10")

For each C in Range1
Call FindMe(C)
Next For
End Sub

Sub FindMe(byval Cell as Range)
msgBox Cell.Address
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top