Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
J@Y J@Y is offline
external usenet poster
 
Posts: 127
Default Type of variable

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Type of variable


"J@Y" wrote in message
...
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-



  #3   Report Post  
Posted to microsoft.public.excel.programming
J@Y J@Y is offline
external usenet poster
 
Posts: 127
Default Type of variable

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

"Sandusky" wrote:


"J@Y" wrote in message
...
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-




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Type of variable

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
--
HTH...

Jim Thomlinson


"J@Y" wrote:

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.

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
Variable type Confusion D Zandveld Excel Programming 2 March 5th 07 09:07 AM
What data type for Variable? Jeff Armstrong Excel Programming 4 August 6th 04 09:38 PM
Trouble with variable type Ken McLennan[_3_] Excel Programming 2 June 2nd 04 08:04 AM
type variable as argument of a sub Koos Excel Programming 1 October 23rd 03 11:41 AM
Variable Type - help me to solve this choco140 Excel Programming 1 September 28th 03 10:39 AM


All times are GMT +1. The time now is 03:46 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"