Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Row select mode to highlight active row of active cell | Excel Discussion (Misc queries) | |||
run macro although blinking cursor is active in an active cell | Excel Programming | |||
referring to formula in a non active cell from active cell | Excel Discussion (Misc queries) | |||
I need to sort an active sheet using the col of the active cell | Excel Programming | |||
Copy from active sheet and paste into new sheet using info from cell in active | Excel Programming |