Select header and first visible row

nora1212

New Member
Joined
Jan 29, 2021
Messages
15
Office Version
  1. 2010
Platform
  1. Windows
Hi,

I'm trying to select the header of a filtered list and the first row of the filtered list. The equivalent of selecting say A1:J1 manually (with shift) and then moving down one row to select both the header range and the first visible row range. I know it involves the use of "special cells" and "visible cells" but can't quite make anything work?

Thanks for your help
 
Last edited:

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Let's say the filtered range is "A1:J100":
VBA Code:
Dim c As Range
With Range("A1:J100")
    Set c = Union(.Rows(1), .Offset(1).SpecialCells(xlCellTypeVisible).Rows(1))
End With
Debug.Print c.Address
 
Upvote 0
Hi. Thanks for the response but this didn't appear to select any rows. I'd like the header row to be selected, and the next filtered row selected, similar to what i could achieve manually so i can copy and paste elsewhere or print.
Let's say the filtered range is "A1:J100":
VBA Code:
Dim c As Range
With Range("A1:J100")
    Set c = Union(.Rows(1), .Offset(1).SpecialCells(xlCellTypeVisible).Rows(1))
End With
Debug.Print c.Address
 
Upvote 0
Just change :
VBA Code:
Debug.Print c.Address
to:
VBA Code:
c.Select
 
Upvote 0
Solution
You're welcome, glad to help & thanks for the feedback.:)
 
Upvote 0

Forum statistics

Threads
1,214,944
Messages
6,122,392
Members
449,081
Latest member
JAMES KECULAH

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
Back
Top