Home |
Search |
Today's Posts |
#1
|
|||
|
|||
HOW TO JUMP TO THE LAST CELL IN A ROW?
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? |
#2
|
|||
|
|||
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 Mark wrote: 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? -- Dave Peterson |
#3
|
|||
|
|||
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 "Dave Peterson" wrote: 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 Mark wrote: 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? -- Dave Peterson |
#4
|
|||
|
|||
RowNumber = 123
becomes RowNumber = activecell.row Mark wrote: 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 "Dave Peterson" wrote: 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 Mark wrote: 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? -- Dave Peterson -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
how do i enfoce a"auto-tab or jump" to next cell | Excel Discussion (Misc queries) | |||
copying cell names | Excel Discussion (Misc queries) | |||
How do I "CTRL [" (jump to a precedent cell) from a European keybo | Excel Discussion (Misc queries) | |||
GET.CELL | Excel Worksheet Functions | |||
VLookup resulting in a blank cell... | Excel Worksheet Functions |