Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 153
Default Last cell in active row--I know, I'm sorry

Greetings all. I know this question has been asked here many, many times,
but I can not get any of the examples to do exactly what I need. I need to
select the last cell with data on the acive row. So, for example, if I have
cell A1 selected, and there are data in cells A2, A5, and A8, I need a macro
to select A8. If, then, I select B3, and there are data in B1, B3, and B10,
I need it to then select B10. Any ideas? Thank you, and again, I apologize
for the redundant question.

Greg
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Last cell in active row--I know, I'm sorry

Copy this function to your standard module1 in the VBE. Then in the code
that you are writing you would assign the last row variable like:

lstRw = lastRow(Worksheets(1))

Then use lstRw to designate your cell references like:

Cells(lstRw, 1) would be a cell that intersects Column A and last row.

Function lastRow(sh As Worksheet) 'Finds last cell with data in the last
used row.
On Error Resume Next
lastRow = sh.Cells.Find(What:="*", After:=sh.Range("A1"), LookAt:=xlPart,
_ LookIn:=xlFormulas, SearchOrder:=xlByRows,
SearchDirection:=xlPrevious, _ MatchCase:=False).Row
On Error GoTo 0
End Function

"Greg Snidow" wrote:

Greetings all. I know this question has been asked here many, many times,
but I can not get any of the examples to do exactly what I need. I need to
select the last cell with data on the acive row. So, for example, if I have
cell A1 selected, and there are data in cells A2, A5, and A8, I need a macro
to select A8. If, then, I select B3, and there are data in B1, B3, and B10,
I need it to then select B10. Any ideas? Thank you, and again, I apologize
for the redundant question.

Greg

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Last cell in active row--I know, I'm sorry

Try

Sub LastCellInOneRow()
Dim LastCol As Long
LastCol = Cells(ActiveCell.Row, Columns.Count).End(xlToLeft).Column
Cells(ActiveCell.Row, LastCol).Select
End Sub


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Greg Snidow" wrote in message ...
Greetings all. I know this question has been asked here many, many times,
but I can not get any of the examples to do exactly what I need. I need to
select the last cell with data on the acive row. So, for example, if I have
cell A1 selected, and there are data in cells A2, A5, and A8, I need a macro
to select A8. If, then, I select B3, and there are data in B1, B3, and B10,
I need it to then select B10. Any ideas? Thank you, and again, I apologize
for the redundant question.

Greg

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
Row select mode to highlight active row of active cell Bart Fay[_2_] Excel Discussion (Misc queries) 0 May 11th 10 09:34 PM
run macro although blinking cursor is active in an active cell bartman1980 Excel Programming 1 December 20th 07 11:29 AM
referring to formula in a non active cell from active cell nickname Excel Discussion (Misc queries) 1 June 21st 07 12:11 PM
I need to sort an active sheet using the col of the active cell HamFlyer Excel Programming 3 June 6th 06 07:25 PM
Copy from active sheet and paste into new sheet using info from cell in active Ingve Excel Programming 3 January 23rd 06 09:57 PM


All times are GMT +1. The time now is 03:52 PM.

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

About Us

"It's about Microsoft Excel"