![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Apr 2002
Posts: 50
|
I am trying to write a macro that will allow an undo. With a selected cells loop i want to find the last cell in each row of the selected cells.
cell.End(xlToRight).Column works fine unless there is an empty cell part way along the row, in which case it selects the cell to the left of the blank. Is there a way to find the rightmost column ignoring blanks? Thx |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Apr 2002
Posts: 113
|
You can also search VB help for usedrange (or rangeused?), but that would be the futhermost column used in the spreadsheet, which is probably not what you want.
Search this board for last cell in column and you'll find various VB and equations to return the value or row of the last used cell in a column. You could adapt to rows. |
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
|
Hi,
At least a couple of ways through code. Code:
With ActiveSheet
.UsedRange
LastCol = .Cells.SpecialCells(xlCellTypeLastCell).Column
LastRow = .Cells.SpecialCells(xlCellTypeLastCell).Row
End With
or
LastCol = Range("IV1").End(xlToLeft).Column
HTH, Jay |
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Apr 2002
Posts: 50
|
Cheers guys - Jay those specialcells do the trick!! many thanks - sid
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|