Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default Passing a range in a macro call

Excel 2002, WinXP
I feel a little silly asking this question, but I have tried every which way
to do this to no avail.
When calling one macro from another, how do you pass a range in the call?
Not the value of the range, but the range itself. Say it's MyRng. Thanks
for your help. Otto


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Passing a range in a macro call

Hi
sub foo_main()
dim myrng as range
set myrng=activesheet.range("A1:B2")
foo_sub(myrng)
end sub

sub foo_sub(rng as range)
dim cell as range
for each cell in rng
msgbox cell.value
next
end sub

"Otto Moehrbach" wrote:

Excel 2002, WinXP
I feel a little silly asking this question, but I have tried every which way
to do this to no avail.
When calling one macro from another, how do you pass a range in the call?
Not the value of the range, but the range itself. Say it's MyRng. Thanks
for your help. Otto



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default Passing a range in a macro call

Frank
Thanks for your help but there is a problem with it. I get an "Object
required." error in the foo-main macro on line "foo_sub (myrng)". Otto
"Frank Kabel" wrote in message
...
Hi
sub foo_main()
dim myrng as range
set myrng=activesheet.range("A1:B2")
foo_sub(myrng)
end sub

sub foo_sub(rng as range)
dim cell as range
for each cell in rng
msgbox cell.value
next
end sub

"Otto Moehrbach" wrote:

Excel 2002, WinXP
I feel a little silly asking this question, but I have tried every which
way
to do this to no avail.
When calling one macro from another, how do you pass a range in the call?
Not the value of the range, but the range itself. Say it's MyRng.
Thanks
for your help. Otto





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Passing a range in a macro call

That is because Frank has committed a serious syntax error. when calling a
subroutine (without using call) you don't enclose the arguments in Parens -
else they will be evaluated such as the error you have now.

foo_sub(myrng)

should be

foo_sub myrng

or

Call foo_sub(myrng)

--
Regards,
Tom Ogilvy


"Otto Moehrbach" wrote in message
...
Frank
Thanks for your help but there is a problem with it. I get an "Object
required." error in the foo-main macro on line "foo_sub (myrng)". Otto
"Frank Kabel" wrote in message
...
Hi
sub foo_main()
dim myrng as range
set myrng=activesheet.range("A1:B2")
foo_sub(myrng)
end sub

sub foo_sub(rng as range)
dim cell as range
for each cell in rng
msgbox cell.value
next
end sub

"Otto Moehrbach" wrote:

Excel 2002, WinXP
I feel a little silly asking this question, but I have tried every

which
way
to do this to no avail.
When calling one macro from another, how do you pass a range in the

call?
Not the value of the range, but the range itself. Say it's MyRng.
Thanks
for your help. Otto







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Passing a range in a macro call

Hi Tom
thanks for the correction. should have run it first in the VBA editor(one of
my common mistakes...)

"Tom Ogilvy" wrote:

That is because Frank has committed a serious syntax error. when calling a
subroutine (without using call) you don't enclose the arguments in Parens -
else they will be evaluated such as the error you have now.

foo_sub(myrng)

should be

foo_sub myrng

or

Call foo_sub(myrng)

--
Regards,
Tom Ogilvy


"Otto Moehrbach" wrote in message
...
Frank
Thanks for your help but there is a problem with it. I get an "Object
required." error in the foo-main macro on line "foo_sub (myrng)". Otto
"Frank Kabel" wrote in message
...
Hi
sub foo_main()
dim myrng as range
set myrng=activesheet.range("A1:B2")
foo_sub(myrng)
end sub

sub foo_sub(rng as range)
dim cell as range
for each cell in rng
msgbox cell.value
next
end sub

"Otto Moehrbach" wrote:

Excel 2002, WinXP
I feel a little silly asking this question, but I have tried every

which
way
to do this to no avail.
When calling one macro from another, how do you pass a range in the

call?
Not the value of the range, but the range itself. Say it's MyRng.
Thanks
for your help. Otto










  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Passing a range in a macro call

Sub Main()
Dim rng as Range
set rng = Range("A1")
processRange rgn
End Sub

Sub ProcessRange(MyRange as Range)
msgbox typename(MyRange)
End Sub

--
Regards,
Tom Ogilvy

"Otto Moehrbach" wrote in message
...
Excel 2002, WinXP
I feel a little silly asking this question, but I have tried every which

way
to do this to no avail.
When calling one macro from another, how do you pass a range in the call?
Not the value of the range, but the range itself. Say it's MyRng. Thanks
for your help. Otto




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default Passing a range in a macro call

Tom
You have come to the rescue again. I know to use "Call" when calling a
macro and passing something. But this time it completely slipped my mind.
Thanks. Otto
"Tom Ogilvy" wrote in message
...
Sub Main()
Dim rng as Range
set rng = Range("A1")
processRange rgn
End Sub

Sub ProcessRange(MyRange as Range)
msgbox typename(MyRange)
End Sub

--
Regards,
Tom Ogilvy

"Otto Moehrbach" wrote in message
...
Excel 2002, WinXP
I feel a little silly asking this question, but I have tried every which

way
to do this to no avail.
When calling one macro from another, how do you pass a range in the call?
Not the value of the range, but the range itself. Say it's MyRng.
Thanks
for your help. Otto






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
passing arguments from an excel macro to a word macro KWE39 Excel Discussion (Misc queries) 1 July 7th 05 03:56 PM
Stored Procedure call and passing parameters TLowe Excel Programming 3 April 23rd 04 10:09 AM
passing variables from an excel macro to a powerpoint macro jake Excel Programming 1 December 11th 03 02:36 AM
Passing range as argument Jan Kronsell[_2_] Excel Programming 3 September 3rd 03 12:31 PM
Passing range to subprocedure - maybe? Mike Gerbracht Excel Programming 2 July 26th 03 02:44 AM


All times are GMT +1. The time now is 03:37 PM.

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"