Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 252
Default Pass a range object as a parameter

Hi all,

How to pass a range object instead of to pass it's default value?

Clara
--
thank you so much for your help
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Pass a range object as a parameter

Clara,

You would pass it like Range("A1") for example. The important part is that
the called sub or function must be expecting a range. To demonstrate, paste
the code below in a module. Run the test sub. You will see that Range("A1")
is passed to the two subroutines but PassTheRange gets the range object
because it is expecting a range. PassTheValue gets the default value because
it is expecting a string value.


Sub test()
PassTheRange Range("A1")
PassTheValue Range("A1")
End Sub
Sub PassTheValue(strValue As String)
Debug.Print strValue
End Sub
Sub PassTheRange(r As Range)
Debug.Print r.Address
End Sub




--
Hope that helps.

Vergel Adriano


"clara" wrote:

Hi all,

How to pass a range object instead of to pass it's default value?

Clara
--
thank you so much for your help

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 252
Default Pass a range object as a parameter

Hi Vergel,

Thank you very much! Syntax I used is like "SubName (RangeObjcet)", it
doesn't work, but when I use "Call SubName(RangeObject)" it works.

Clara


--
thank you so much for your help


"Vergel Adriano" wrote:

Clara,

You would pass it like Range("A1") for example. The important part is that
the called sub or function must be expecting a range. To demonstrate, paste
the code below in a module. Run the test sub. You will see that Range("A1")
is passed to the two subroutines but PassTheRange gets the range object
because it is expecting a range. PassTheValue gets the default value because
it is expecting a string value.


Sub test()
PassTheRange Range("A1")
PassTheValue Range("A1")
End Sub
Sub PassTheValue(strValue As String)
Debug.Print strValue
End Sub
Sub PassTheRange(r As Range)
Debug.Print r.Address
End Sub




--
Hope that helps.

Vergel Adriano


"clara" wrote:

Hi all,

How to pass a range object instead of to pass it's default value?

Clara
--
thank you so much for your help

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Pass a range object as a parameter

Hi Clara,

to call sub procedures, you can use

Call SubName(RangeObject)

or

SubName RangeObject




--
Hope that helps.

Vergel Adriano


"clara" wrote:

Hi Vergel,

Thank you very much! Syntax I used is like "SubName (RangeObjcet)", it
doesn't work, but when I use "Call SubName(RangeObject)" it works.

Clara


--
thank you so much for your help


"Vergel Adriano" wrote:

Clara,

You would pass it like Range("A1") for example. The important part is that
the called sub or function must be expecting a range. To demonstrate, paste
the code below in a module. Run the test sub. You will see that Range("A1")
is passed to the two subroutines but PassTheRange gets the range object
because it is expecting a range. PassTheValue gets the default value because
it is expecting a string value.


Sub test()
PassTheRange Range("A1")
PassTheValue Range("A1")
End Sub
Sub PassTheValue(strValue As String)
Debug.Print strValue
End Sub
Sub PassTheRange(r As Range)
Debug.Print r.Address
End Sub




--
Hope that helps.

Vergel Adriano


"clara" wrote:

Hi all,

How to pass a range object instead of to pass it's default value?

Clara
--
thank you so much for your help

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 182
Default Pass a range object as a parameter

Hi,

Just add some...
If we call a procedure with arguments we have to include the correct
arguments or variable...
like :
Call SubName(RangeObject) or
SubName RangeObject

--

Regards,

Halim


"Vergel Adriano" wrote:

Hi Clara,

to call sub procedures, you can use

Call SubName(RangeObject)

or

SubName RangeObject




--
Hope that helps.

Vergel Adriano


"clara" wrote:

Hi Vergel,

Thank you very much! Syntax I used is like "SubName (RangeObjcet)", it
doesn't work, but when I use "Call SubName(RangeObject)" it works.

Clara


--
thank you so much for your help


"Vergel Adriano" wrote:

Clara,

You would pass it like Range("A1") for example. The important part is that
the called sub or function must be expecting a range. To demonstrate, paste
the code below in a module. Run the test sub. You will see that Range("A1")
is passed to the two subroutines but PassTheRange gets the range object
because it is expecting a range. PassTheValue gets the default value because
it is expecting a string value.


Sub test()
PassTheRange Range("A1")
PassTheValue Range("A1")
End Sub
Sub PassTheValue(strValue As String)
Debug.Print strValue
End Sub
Sub PassTheRange(r As Range)
Debug.Print r.Address
End Sub




--
Hope that helps.

Vergel Adriano


"clara" wrote:

Hi all,

How to pass a range object instead of to pass it's default value?

Clara
--
thank you so much for your help



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Pass a range object as a parameter

Halim,
Whilst it is normal to follow that convention, the brackets have a meaning
themseleves as to how the arguments are passed. Check the debug output of
these examples below to see the trend:

Private Sub CommandButton1_Click()
Dim Arg1Value As Double
Dim Arg2Value As String

Arg1Value = Sin(22 / 7)
Arg2Value = "some string"
MySub1 Arg1Value, Arg2Value
Debug.Print Arg1Value, Arg2Value

Arg1Value = Sin(22 / 7)
Arg2Value = "some string"
MySub1 (Arg1Value)
Debug.Print Arg1Value, Arg2Value

Arg1Value = Sin(22 / 7)
Arg2Value = "some string"
Call MySub1(Arg1Value)
Debug.Print Arg1Value, Arg2Value

Arg1Value = Sin(22 / 7)
Arg2Value = "some string"
MySub1 (Arg1Value), (Arg2Value)
Debug.Print Arg1Value, Arg2Value

Arg1Value = Sin(22 / 7)
Arg2Value = "some string"
Call MySub1((Arg1Value), (Arg2Value))
Debug.Print Arg1Value, Arg2Value

Arg1Value = Sin(22 / 7)
Arg2Value = "some string"
Call MySub1(Arg1Value, Arg2Value)
Debug.Print Arg1Value, Arg2Value

End Sub

Sub MySub1(ByRef arg1 As Double, Optional ByRef arg2 As String)
arg1 = 10
arg2 = "New string"
End Sub

NickHK

"Halim" wrote in message
...
Hi,

Just add some...
If we call a procedure with arguments we have to include the correct
arguments or variable...
like :
Call SubName(RangeObject) or
SubName RangeObject

--

Regards,

Halim


"Vergel Adriano" wrote:

Hi Clara,

to call sub procedures, you can use

Call SubName(RangeObject)

or

SubName RangeObject




--
Hope that helps.

Vergel Adriano


"clara" wrote:

Hi Vergel,

Thank you very much! Syntax I used is like "SubName (RangeObjcet)", it
doesn't work, but when I use "Call SubName(RangeObject)" it works.

Clara


--
thank you so much for your help


"Vergel Adriano" wrote:

Clara,

You would pass it like Range("A1") for example. The important part

is that
the called sub or function must be expecting a range. To

demonstrate, paste
the code below in a module. Run the test sub. You will see that

Range("A1")
is passed to the two subroutines but PassTheRange gets the range

object
because it is expecting a range. PassTheValue gets the default

value because
it is expecting a string value.


Sub test()
PassTheRange Range("A1")
PassTheValue Range("A1")
End Sub
Sub PassTheValue(strValue As String)
Debug.Print strValue
End Sub
Sub PassTheRange(r As Range)
Debug.Print r.Address
End Sub




--
Hope that helps.

Vergel Adriano


"clara" wrote:

Hi all,

How to pass a range object instead of to pass it's default value?

Clara
--
thank you so much for your help



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
Pass date parameter into MS Query Richard Edwards Excel Discussion (Misc queries) 2 June 20th 08 11:43 AM
Is it possible to pass a parameter into IN operator in Query? DennisS Excel Discussion (Misc queries) 0 June 26th 07 09:27 AM
Error 424 Object Required when passing range as parameter carrick Excel Programming 2 June 29th 06 11:05 PM
How to: Pass Command Line Parameter ??? Webtest Excel Worksheet Functions 0 October 24th 05 05:27 PM
How to pass a workshhet name as a parameter into a subroutine ? yigalb Excel Discussion (Misc queries) 4 January 9th 05 10:28 AM


All times are GMT +1. The time now is 10:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"