Change the fixed row number to the second visible row after applying the filter

An Quala

Board Regular
Joined
Mar 21, 2022
Messages
146
Office Version
  1. 2021
Platform
  1. Windows
I want to select the second row # visible after applying the filter, currently it is "2:2" but I want it to be the second row # as first one is the header and then go down and select the visible range, can anyone help me in correcting this?

Thank you.


VBA Code:
Sub Justtesting()

    Sheets("Sponsored Products").Select
    Cells.Select
    Selection.AutoFilter
    ActiveSheet.Range("$A$1:$AQ$" & Cells(Rows.Count, "A").End(xlUp).Row).AutoFilter Field:=2, Criteria1:=Array( _
        "Ad Group", "Bidding Adjustment", "Campaign", "Negative Keyword", "Product Ad", "=") _
        , Operator:=xlFilterValues
    Rows("2:2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Delete Shift:=xlUp

End Sub
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
When working in vba it is rarely required to actually select worksheets, ranges etc to work with them. Further, doing so slows your code.
Guessing a bit at what you are trying to achieve, try this with a copy of your workbook.

VBA Code:
Sub Justtesting_Alternative()
  With Sheets("Sponsored Products")
    With .Range("$A$1:$AQ$" & .Cells(Rows.Count, "A").End(xlUp).Row)
      .AutoFilter Field:=2, Criteria1:= _
        Array("Ad Group", "Bidding Adjustment", "Campaign", "Negative Keyword", "Product Ad", "="), Operator:=xlFilterValues
      .Offset(1).Resize(.Rows.Count - 1).EntireRow.Delete
      .AutoFilter Field:=2
    End With
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,006
Messages
6,122,665
Members
449,091
Latest member
peppernaut

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