Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Mark
 
Posts: n/a
Default 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   Report Post  
Dave Peterson
 
Posts: n/a
Default

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   Report Post  
Mark
 
Posts: n/a
Default

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   Report Post  
Dave Peterson
 
Posts: n/a
Default

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i enfoce a"auto-tab or jump" to next cell Mike in Bangkok Excel Discussion (Misc queries) 5 March 22nd 06 09:42 AM
copying cell names Al Excel Discussion (Misc queries) 12 August 11th 05 03:01 PM
How do I "CTRL [" (jump to a precedent cell) from a European keybo Tim Stucka Excel Discussion (Misc queries) 1 February 17th 05 03:55 PM
GET.CELL Biff Excel Worksheet Functions 2 November 24th 04 07:16 PM
VLookup resulting in a blank cell... KempensBoerke Excel Worksheet Functions 1 October 28th 04 09:57 PM


All times are GMT +1. The time now is 02:53 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"