Autofilter and header row

ge0rge

Active Member
Joined
Feb 24, 2009
Messages
262
I have two header type rows on my worksheet. I am using this code to autofilter the sheet:
Code:
Private Sub cmdSort_Click()
If UserForm1.txtParts.Value = "" Then
Exit Sub
End If
Columns("B:B").Select
    Selection.AutoFilter
    Selection.AutoFilter Field:=1, Criteria1:=UserForm1.txtParts.Value
Unload Me
End Sub

When it filters, I lose my header rows (rows 1 & 2). I really want to filter from Row3 and on. Is this possible? Thanks.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Try this instead:
Code:
Private Sub cmdSort_Click()
Dim i as Long
If UserForm1.txtParts.Value = "" Then Exit Sub
i = Range("B" & Rows.Count).End(xlUp).Row
With Range("B3:B" & i)
    .AutoFilter
    .AutoFilter Field:=1, Criteria1:=UserForm1.txtParts.Value
End With
Unload Me
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,570
Messages
6,179,610
Members
452,931
Latest member
The Monk

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