Last cell in active row--I know, I'm sorry
Copy this function to your standard module1 in the VBE. Then in the code
that you are writing you would assign the last row variable like:
lstRw = lastRow(Worksheets(1))
Then use lstRw to designate your cell references like:
Cells(lstRw, 1) would be a cell that intersects Column A and last row.
Function lastRow(sh As Worksheet) 'Finds last cell with data in the last
used row.
On Error Resume Next
lastRow = sh.Cells.Find(What:="*", After:=sh.Range("A1"), LookAt:=xlPart,
_ LookIn:=xlFormulas, SearchOrder:=xlByRows,
SearchDirection:=xlPrevious, _ MatchCase:=False).Row
On Error GoTo 0
End Function
"Greg Snidow" wrote:
Greetings all. I know this question has been asked here many, many times,
but I can not get any of the examples to do exactly what I need. I need to
select the last cell with data on the acive row. So, for example, if I have
cell A1 selected, and there are data in cells A2, A5, and A8, I need a macro
to select A8. If, then, I select B3, and there are data in B1, B3, and B10,
I need it to then select B10. Any ideas? Thank you, and again, I apologize
for the redundant question.
Greg
|