ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Setting Range Dynamically (https://www.excelbanter.com/excel-discussion-misc-queries/121843-setting-range-dynamically.html)

DJS

Setting Range Dynamically
 
Hello, I am trying to set Range dynamically with a variable and just can't
seem to figure out the proper method. Any help greatly appreciated. Plus, if
someone knows a great tutorial on how to use Range, Cells, etc that would be
appreciated also!

Here is my code snippet which does not seem to properly define the range
(Note: My var, colNum, is properly populating the column number field):

Set rng = Range(Range(Cells(2, colNum)), Range(Cells(2, colNum)).End(xlDown))

TIA

Jim Thomlinson

Setting Range Dynamically
 
On the up side you are really close... Try this...

Set rng = Range(Cells(2, colNum), Cells(2, colNum).End(xlDown))
--
HTH...

Jim Thomlinson


"DJS" wrote:

Hello, I am trying to set Range dynamically with a variable and just can't
seem to figure out the proper method. Any help greatly appreciated. Plus, if
someone knows a great tutorial on how to use Range, Cells, etc that would be
appreciated also!

Here is my code snippet which does not seem to properly define the range
(Note: My var, colNum, is properly populating the column number field):

Set rng = Range(Range(Cells(2, colNum)), Range(Cells(2, colNum)).End(xlDown))

TIA


Gary''s Student

Setting Range Dynamically
 
Colnum = 5
Set rng = Range(Cells(2, Colnum), Cells(2, Colnum).End(xlDown))

just put the "down" reference in the range function.
--
Gary's Student


"DJS" wrote:

Hello, I am trying to set Range dynamically with a variable and just can't
seem to figure out the proper method. Any help greatly appreciated. Plus, if
someone knows a great tutorial on how to use Range, Cells, etc that would be
appreciated also!

Here is my code snippet which does not seem to properly define the range
(Note: My var, colNum, is properly populating the column number field):

Set rng = Range(Range(Cells(2, colNum)), Range(Cells(2, colNum)).End(xlDown))

TIA


DJS

Setting Range Dynamically
 
Thanks Jim, I tried that (still have it commented out) but now it works like
a charm. BTW: Do you know how to echo out to the msg window the Range whch
will be used? I tried the following but doesn't seem to work:

MsgBox "The selected Range is " & rng.Text

Thanks again.

"Jim Thomlinson" wrote:

On the up side you are really close... Try this...

Set rng = Range(Cells(2, colNum), Cells(2, colNum).End(xlDown))
--
HTH...

Jim Thomlinson


"DJS" wrote:

Hello, I am trying to set Range dynamically with a variable and just can't
seem to figure out the proper method. Any help greatly appreciated. Plus, if
someone knows a great tutorial on how to use Range, Cells, etc that would be
appreciated also!

Here is my code snippet which does not seem to properly define the range
(Note: My var, colNum, is properly populating the column number field):

Set rng = Range(Range(Cells(2, colNum)), Range(Cells(2, colNum)).End(xlDown))

TIA


Bob Phillips

Setting Range Dynamically
 
MsgBox "The selected Range is " & rng.Address

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"DJS" wrote in message
...
Thanks Jim, I tried that (still have it commented out) but now it works
like
a charm. BTW: Do you know how to echo out to the msg window the Range whch
will be used? I tried the following but doesn't seem to work:

MsgBox "The selected Range is " & rng.Text

Thanks again.

"Jim Thomlinson" wrote:

On the up side you are really close... Try this...

Set rng = Range(Cells(2, colNum), Cells(2, colNum).End(xlDown))
--
HTH...

Jim Thomlinson


"DJS" wrote:

Hello, I am trying to set Range dynamically with a variable and just
can't
seem to figure out the proper method. Any help greatly appreciated.
Plus, if
someone knows a great tutorial on how to use Range, Cells, etc that
would be
appreciated also!

Here is my code snippet which does not seem to properly define the
range
(Note: My var, colNum, is properly populating the column number field):

Set rng = Range(Range(Cells(2, colNum)), Range(Cells(2,
colNum)).End(xlDown))

TIA




DJS

Setting Range Dynamically
 
Thank you!

"Bob Phillips" wrote:

MsgBox "The selected Range is " & rng.Address

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"DJS" wrote in message
...
Thanks Jim, I tried that (still have it commented out) but now it works
like
a charm. BTW: Do you know how to echo out to the msg window the Range whch
will be used? I tried the following but doesn't seem to work:

MsgBox "The selected Range is " & rng.Text

Thanks again.

"Jim Thomlinson" wrote:

On the up side you are really close... Try this...

Set rng = Range(Cells(2, colNum), Cells(2, colNum).End(xlDown))
--
HTH...

Jim Thomlinson


"DJS" wrote:

Hello, I am trying to set Range dynamically with a variable and just
can't
seem to figure out the proper method. Any help greatly appreciated.
Plus, if
someone knows a great tutorial on how to use Range, Cells, etc that
would be
appreciated also!

Here is my code snippet which does not seem to properly define the
range
(Note: My var, colNum, is properly populating the column number field):

Set rng = Range(Range(Cells(2, colNum)), Range(Cells(2,
colNum)).End(xlDown))

TIA






All times are GMT +1. The time now is 01:26 AM.

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