Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Pass date parameter into MS Query | Excel Discussion (Misc queries) | |||
Is it possible to pass a parameter into IN operator in Query? | Excel Discussion (Misc queries) | |||
Error 424 Object Required when passing range as parameter | Excel Programming | |||
How to: Pass Command Line Parameter ??? | Excel Worksheet Functions | |||
How to pass a workshhet name as a parameter into a subroutine ? | Excel Discussion (Misc queries) |