Hopefully simple question

entrekin

New Member
Joined
Feb 7, 2014
Messages
2
I am writing a macro that I want to use to select all cells in filtered columns A:P except for the header row, which is always row 1. I've tried using

ActiveCell.SpecialCells(xlLastCell).Select
Range(Selection, Cells(1)).Select

but it selects all the way to A1. What I want is to select from the end to the first visible (based on the filter) cell below A1. I have a feeling the answer is simple, but I can't seem to figure it out. Actually, I thought my code worked the first time I ran it, but every time since then, it has selected all the way to A1. Any ideas?
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,784
Office Version
  1. 2010
Platform
  1. Windows
Code:
    With ActiveSheet.AutoFilter.Range
        .Offset(1).Resize(.Rows.Count - 1).Select
    End With
 

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
Here's one way. Just note that it's generally not necessary to select.

<font face=Calibri><SPAN style="color:#00007F">Sub</SPAN> foo()<br>    <SPAN style="color:#00007F">Dim</SPAN> lr <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>    <br>    lr = Cells(Rows.Count, "A").End(xlUp).Row<br>    <br>    Range("A2:A" & lr).SpecialCells(xlCellTypeVisible).Select<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>

HTH,
 

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,784
Office Version
  1. 2010
Platform
  1. Windows
You're welcome.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,479
Messages
5,636,574
Members
416,925
Latest member
malamutus

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top