HOW TO JUMP TO THE LAST CELL IN A ROW?

M

Mark

I want to write a macro that enters data into the cell following the last
cell in a row, so I need to automatically jump to the last cell, plus one.

How to jump to the last cell in a row?
 
D

Dave Peterson

I like this:

Option Explicit
Sub testme()

Dim RowNumber As Long
Dim LastCellInRow As Range

RowNumber = 123

With ActiveSheet
Set LastCellInRow = .Cells(RowNumber, .Columns.Count).End(xlToLeft)
End With

If IsEmpty(LastCellInRow) Then
'do nothing (we're in column A)
Else
Set LastCellInRow = LastCellInRow.Offset(0, 1)
End If

LastCellInRow.Value = "hi there"

End Sub
 
M

Mark

Thanks a lot, Dave! Cool.

Can I make the row number always relative to the row I'm in when I start the
macro? How would the macro change to do this?

Thanks again,

Mark
 
Top