Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Resize a Range object

Status
Not open for further replies.

pachad

Programmer
Mar 13, 2003
45
0
0
US
Hello all!

I have a Range object which I set as follows ('namedRange' is a named range of cells in the spreadsheet):

Set myRange = Range("namedRange").Resize(numRows, numCols)

Using a loop, I would like to pass to a function each row, with all the columns in that row, for all the rows in the range.

This code, which I tried, does not work:
Code:
Dim lngRowCount as Long
Dim lngCtr as Long

lngRowCount = Range("namedRange").Rows.Count

For lngCtr = 1 to lngRowCount
   Range("namedRange").Resize(lngCtr,Range("namedRange").Columns.Count)
   myFunction Range("namedRange")
Next lngCtr

This code just passes an increasing amount of rows to the function, rather than just a single row for each iteration of the For loop.

Help, please :-0 !
 
You can:

Dim rRow as Range
For Each rRow In Range("namedRange").Rows
....
Next rRow

combo
 
Thanks, but how would I use the resize method if i only wanted to pass a specific row?

 
I have subsequently discovered that I should not use the Resize method to pass a single row...

Code:
For lngCtr = 1 to Range("namedRange").Rows.Count
   myFunction namedRange.Rows(lngCtr)
Next lngCtr

Duh... [hammer]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top