Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 905
Default How to reference variable rectangular range?

I have the following variables:

Const cellName As String = "B2"
Const nRow As Long = 5
Const nCol As Long = 10

I want to reference the rectangular range starting from cellName through row
cellName+nRow and column cellName+nCol; that is, B2:K7 for the values above.

I've come up with the following:

Range(cellName, Range(cellName).Cells(nRow, nCol))

Seems tedious. Is that the best I can do?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default How to reference variable rectangular range?

You would use the Resize property...

Range(cellName).Resize(nRow, nCol)

Note, however, that you counted your rows and columns differently... I get
Column K for nCol equal to 10; but, using the same counting method, I get
Row 6, not Row 7, for nRow = 5.

--
Rick (MVP - Excel)


"Joe User" <joeu2004 wrote in message
...
I have the following variables:

Const cellName As String = "B2"
Const nRow As Long = 5
Const nCol As Long = 10

I want to reference the rectangular range starting from cellName through
row cellName+nRow and column cellName+nCol; that is, B2:K7 for the values
above.

I've come up with the following:

Range(cellName, Range(cellName).Cells(nRow, nCol))

Seems tedious. Is that the best I can do?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 905
Default How to reference variable rectangular range?

"Rick Rothstein" wrote:
Range(cellName).Resize(nRow, nCol)


Thanks.


I get Row 6, not Row 7, for nRow = 5.


My mistake. I was out sick the day they taught counting in kindergarten.
:-)


----- original message -----

"Rick Rothstein" wrote in message
...
You would use the Resize property...

Range(cellName).Resize(nRow, nCol)

Note, however, that you counted your rows and columns differently... I get
Column K for nCol equal to 10; but, using the same counting method, I get
Row 6, not Row 7, for nRow = 5.

--
Rick (MVP - Excel)


"Joe User" <joeu2004 wrote in message
...
I have the following variables:

Const cellName As String = "B2"
Const nRow As Long = 5
Const nCol As Long = 10

I want to reference the rectangular range starting from cellName through
row cellName+nRow and column cellName+nCol; that is, B2:K7 for the values
above.

I've come up with the following:

Range(cellName, Range(cellName).Cells(nRow, nCol))

Seems tedious. Is that the best I can do?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default How to reference variable rectangular range?

Joe, you were not incorrect when you used the example row cellName + nRow.
That would be row 7. But when referenced as Range(cellName).Range(nRow,
nCol) the count for nRow becomes relative to cell B2, not in addition to it.

But Rick gave you the solution with the resize statement so the above is a
moot point.


"Joe User" <joeu2004 wrote in message
...
"Rick Rothstein" wrote:
Range(cellName).Resize(nRow, nCol)


Thanks.


I get Row 6, not Row 7, for nRow = 5.


My mistake. I was out sick the day they taught counting in kindergarten.
:-)


----- original message -----

"Rick Rothstein" wrote in message
...
You would use the Resize property...

Range(cellName).Resize(nRow, nCol)

Note, however, that you counted your rows and columns differently... I
get Column K for nCol equal to 10; but, using the same counting method, I
get Row 6, not Row 7, for nRow = 5.

--
Rick (MVP - Excel)


"Joe User" <joeu2004 wrote in message
...
I have the following variables:

Const cellName As String = "B2"
Const nRow As Long = 5
Const nCol As Long = 10

I want to reference the rectangular range starting from cellName through
row cellName+nRow and column cellName+nCol; that is, B2:K7 for the
values above.

I've come up with the following:

Range(cellName, Range(cellName).Cells(nRow, nCol))

Seems tedious. Is that the best I can do?





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
How to reference variable range? WhatsUp31415 Excel Discussion (Misc queries) 4 May 17th 09 07:20 PM
Making a vertical list from a rectangular range, with no empty lines vsoler Excel Worksheet Functions 10 February 25th 09 03:55 AM
Where is the link? (non-rectangular reference) Michael R Excel Discussion (Misc queries) 4 May 28th 08 10:41 AM
Variable range reference Kyle Szukaitis Excel Discussion (Misc queries) 1 October 21st 05 03:10 AM
Variable Range Reference Bob Excel Programming 3 December 16th 04 04:13 PM


All times are GMT +1. The time now is 12:07 AM.

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"