How to select Visible Cells range minus 2 rows (frozen panes)

L

LuisE

I'm trying to programatically select the visible cells in the current region
except the rows 1 and 2 at the top of the sheet.

Thanks in advance.
 
W

ward376

This will select the current region of the first cell minus two rows:

Cells(1, 1).CurrentRegion.Offset(2, 0).Resize(Cells(1, 1). _
CurrentRegion.Rows.Count - 2, Cells(1,
1).CurrentRegion.Columns.Count).select

Cliff Edwards
 
W

ward376

Or to actually answer your question:

Cells(1, 1).CurrentRegion.Offset(2, 0). _
Resize(Cells(1, 1).CurrentRegion.Rows.Count - 2, _
Cells(1, 1).CurrentRegion.Columns.Count). _
SpecialCells(xlCellTypeVisible).Select

will select only the visible cells.

Cliff Edwards
 
W

ward376

To leave the last row visible:

Cells(1, 1).CurrentRegion.Offset(2, 0). _
Resize(Cells(1, 1).CurrentRegion.Rows.Count - 3, _
Cells(1, 1).CurrentRegion.Columns.Count). _
SpecialCells(xlCellTypeVisible).Select

'explanation: _
..Offset(2, 0) (moves range down two rows) _
_
Resize(Cells(1, 1).CurrentRegion.Rows.Count - 3 _
(tells it the range is 3 rows less than the total number of rows)

Cliff Edwards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top