A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Help please!



 
 
Thread Tools Display Modes
  #1  
Old November 10th, 2009, 03:15 PM posted to microsoft.public.excel.misc
Love Carl Sagan
external usenet poster
 
Posts: 2
Default Help please!

Does anyone have the macro to select the first cell of the last row?



thanks,
Carla


--
There''s no end to learning!
  #2  
Old November 10th, 2009, 03:32 PM posted to microsoft.public.excel.misc
JLatham
external usenet poster
 
Posts: 1,896
Default Help please!

Sub SelectFirstInLast()
ActiveSheet.Range("A" & Rows.Count).End(xlup).Activate
End Sub

I assume by the "first cell" you meant column A.

"Love Carl Sagan" wrote:

Does anyone have the macro to select the first cell of the last row?



thanks,
Carla


--
There''s no end to learning!

  #3  
Old November 10th, 2009, 03:36 PM posted to microsoft.public.excel.misc
Love Carl Sagan
external usenet poster
 
Posts: 2
Default Help please!

Yes, you are correct, I meant column A.

Thanks a lot for your prompt help!

Carla




--
There''''s no end to learning!


"JLatham" wrote:

Sub SelectFirstInLast()
ActiveSheet.Range("A" & Rows.Count).End(xlup).Activate
End Sub

I assume by the "first cell" you meant column A.

"Love Carl Sagan" wrote:

Does anyone have the macro to select the first cell of the last row?



thanks,
Carla


--
There''s no end to learning!

  #4  
Old November 10th, 2009, 03:44 PM posted to microsoft.public.excel.misc
JLatham
external usenet poster
 
Posts: 1,896
Default Help please!

The previous response made some assumptions that might not be true, so here
is a macro that makes no assumptions: it finds the last used row on the sheet
based on the columns in UsedRange and then finds the first non-empty cell on
that row.

This process takes into account things like "ragged" last row entries; i.e.
where not all used columns may have an equal number of entries, and also
disregards the current UsedRange value since you may have deleted entries in
rows/columns which would cause UsedRange to be incorrect.

Sub FirstOfLast()
Dim FirstColumn As Integer
Dim LastRow As Long
Dim testRow As Long
Dim LC As Integer

FirstColumn = Columns.Count + 1 ' make larger than possible response
For LC = 1 To ActiveSheet.UsedRange.Columns.Count
testRow = Cells(Rows.Count, LC).End(xlUp).Row
If testRow LastRow Then
LastRow = testRow
End If
Next
If Not IsEmpty(Cells(LastRow, 1)) Then
FirstColumn = 1
Else
FirstColumn = Cells(LastRow, 1).End(xlToRight).Column
End If
'select first used cell in last used row
Cells(LastRow, FirstColumn).Activate
End Sub


"Love Carl Sagan" wrote:

Does anyone have the macro to select the first cell of the last row?



thanks,
Carla


--
There''s no end to learning!

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:44 PM.


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