Getting a range using row & col numbers?

N

Net Doe

Is this an efficient way to do this? (Code means nothing except
to illustrate)

' Get a certain range using passed-in row and column values
Function getRange(r as integer, c as integer) as Range
const maxr = 10
const maxc = 10
dim rng as Range
rng = Range(Cells(r, c), Cells(maxr, maxc))
end Function

IOW is this a good way to refer to a Range instead of doing
Range("A1:J10") syntax. I DO want the function signature to
have a row and column parms, unless there's a better generic
way.

Thsnks!
 
J

Jim Cone

Function getRange(ByRef r As Long, ByRef c As Long) As Excel.Range
Set getRange = Range(Range("J10"), Cells(r, c))
End Function

Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)


"Net Doe"
wrote in message
Is this an efficient way to do this? (Code means nothing except
to illustrate)

' Get a certain range using passed-in row and column values
Function getRange(r as integer, c as integer) as Range
const maxr = 10
const maxc = 10
dim rng as Range
rng = Range(Cells(r, c), Cells(maxr, maxc))
end Function

IOW is this a good way to refer to a Range instead of doing
Range("A1:J10") syntax. I DO want the function signature to
have a row and column parms, unless there's a better generic
way.
Thsnks!
 
N

Net Doe

But this limits it to "J10". I want tp"fully" parameterize
the start/stop rows/cols, so the ByRef r and c are not
even necessary. I should have pseudo-coded it
this way

' Give me the Range of cells from (r1,c1) to (r2,c2)
Function getRange(r1 as integer, c1 as integer _
r2 as integer, c2 as integer) as Range
dim rng as Range
rng = Range(Cells(r1, c1), Cells(r2, c2))
end Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top