ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Passing Arguments in Excell (https://www.excelbanter.com/excel-worksheet-functions/130521-passing-arguments-excell.html)

UB

Passing Arguments in Excell
 
Hi,
Is there a way , I can pass arguments in Excell worksheet object ' Range'
when writing VBA code.
Ex: worksheet.range("a1:c1")
Can I pass arguments to the range object for the cell reference ( a1 & c1).
Thanks

Niek Otten

Passing Arguments in Excell
 
If you don't use the quotes, you can use variables. A mix is also possible.

Let's say VarA' value is "A" and VarB's value is "B2"

Then you could use Range(VarA & "2:" & VarB) to mean Range("A2:B2")

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

"ub" wrote in message ...
| Hi,
| Is there a way , I can pass arguments in Excell worksheet object ' Range'
| when writing VBA code.
| Ex: worksheet.range("a1:c1")
| Can I pass arguments to the range object for the cell reference ( a1 & c1).
| Thanks



UB

Passing Arguments in Excell
 
Hi
How do I write the code , when I want to pass the value of a cell in the
range object.
Example, I have stored a value of a cell in a variable 'I'.
Now I want my range to be from A1 to C(the variable 'I').
Please advise.

"Niek Otten" wrote:

If you don't use the quotes, you can use variables. A mix is also possible.

Let's say VarA' value is "A" and VarB's value is "B2"

Then you could use Range(VarA & "2:" & VarB) to mean Range("A2:B2")

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

"ub" wrote in message ...
| Hi,
| Is there a way , I can pass arguments in Excell worksheet object ' Range'
| when writing VBA code.
| Ex: worksheet.range("a1:c1")
| Can I pass arguments to the range object for the cell reference ( a1 & c1).
| Thanks




JE McGimpsey

Passing Arguments in Excell
 
One way:

Dim rMyRange As Range
Set rMyRange = ActiveSheet.Range("A1:C" & I)

In article ,
ub wrote:

How do I write the code , when I want to pass the value of a cell in the
range object.
Example, I have stored a value of a cell in a variable 'I'.
Now I want my range to be from A1 to C(the variable 'I').



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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com