Quote:
|
Typically I would be looking for an empty cell.
|
That's what I thought. If - and
only if - you have no blank cells in the middle of the range, all you need to do is initialize two counters: one for the rows and one for columns. For the row counter, you might code
Code:
Dim RowCntr As Long, ColCntr As Long, RngEnd As String, DataRng As Range
RowCntr = 1 'If you use column headings, or have blank rows on top, start with the correct row instead of 1
Do While Range("A" & RowCntr) > " "
RowCntr = RowCntr + 1
Loop
Of course at this point you've gone beyond the end of your data, so add
Code:
RowCntr = RowCntr - 1
Now you're back into the data.
Now do the column thing. This is different, though, because there's no way to increment columns directly in VBA, so you have to use the Chr() function. It's the same concept as before, only you don't start with 1.
Code:
ColCntr = 65
Do While Range(Chr(ColCntr) & "1") > " " 'Chr(65) = "A"
ColCntr = ColCntr + 1
Loop
ColCntr = ColCntr - 1
Now you've identified the lower right-hand corner of the range.
Code:
RngEnd = Chr(ColCntr) & CStr(RowCntr)
DataRng = "A1:" & RngEnd
If you do have blank cells, or if your data goes beyond column 'Z', you need an entirely different algorithm, but first things first.
Hope This Helps,
Sam