HOW TO JUMP TO THE LAST CELL IN A ROW?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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?
 
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
 
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
 

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

Back
Top