Finding the first and last row numbers from a range variable

Viewed 2616

I have some code I'm working with that has excel ranges saved in variables. I need a way to find the first and the last rows of these range variables. I prefer not to use the xlend(down).row method if at all possible. I guess I could put it into an array and get the lbound and ubound values, but that seems like a lot of work for a pretty simple task. Any simple solutions to the problem?

This is what I have as an example:

sub test()
dim r as range
dim x as integer
dim y as integer

set r as worksheets("sheet1").Range("A1:A7")
x = r.rows 'this gets me the first row in the range
y = r.lastrow 'this isn't valid, but I need something that will do the equivalent of this pseudo code
end sub
1 Answers
Related