Selecting second row after doing the filter

Jalal Kasmani

Board Regular
Joined
Feb 14, 2015
Messages
52
Office Version
  1. 365
Platform
  1. Windows
After filter, i want the cursor on the second row, then select that row and dragdown. can anyone help ?
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Can i kindly get the links of all other codes like pivot, range, loops etc Thanks!
 
Upvote 0
Upvote 0
hi,

the code which you provided does not work if the data starts from fourth row.

Sub filter()


Dim c As Long, r As Long


c = Cells(1, Columns.Count).End(xlToLeft).Column
r = Cells(Rows.Count, c).End(xlUp).Row

With ActiveSheet.Range("a1", Cells(r, c))
.AutoFilter field:=5, Criteria1:="10"
On Error Resume Next
'.Offset(1, 0).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).ClearContents 'to clear the cells

'.Offset(1, 0).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).EntireRow.Delete 'to delete entire row
On Error GoTo 0
.AutoFilter
End With

i want to dynamically filter the data bcoz sometimes my data starts from row second and sometimes from 3rd or 4th .
 
Upvote 0
Code:
 With ActiveSheet.Range("a[COLOR="#FF0000"][B]4[/B][/COLOR]", Cells(r, c))
 
Upvote 0
And i need to change the below code as well

c = Cells(4, Columns.Count).End(xlToLeft).Column

But the user wont be able to change the codes every month. i want whenever i open the file ,,, from whichever row the data is starting i want to filter that and do my workings accordingly.
 
Upvote 0
Code:
Sub Macro2()
    '
    ' Macro2 Macro
    '

    Dim x As Long, c As Long, r As Long

    With ActiveSheet
        c = .Cells.Find(What:="*", SearchOrder:=xlColumns, SearchDirection:=xlPrevious, LookIn:=xlValues).Column
        r = .Cells(Rows.Count, c).End(xlUp).Row
        x = .Range("A1").End(xlDown).Row
        With .Range("a" & x, Cells(r, c))
            .AutoFilter field:=5, Criteria1:="10"
            On Error Resume Next
            '.Offset(1, 0).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).ClearContents 'to clear the cells

            '.Offset(1, 0).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).EntireRow.Delete 'to delete entire row
            On Error GoTo 0
            .AutoFilter


        End With
    End With

End Sub
 
Upvote 0
Try


Rich (BB code):
Sub Macro2()

    Dim x As Long, c As Long, r As Long

    With ActiveSheet
        c = .Cells.Find(What:="*", SearchOrder:=xlColumns, SearchDirection:=xlPrevious, LookIn:=xlValues).Column
        r = .Cells(Rows.Count, c).End(xlUp).Row

        If .Cells(1, 1) <> "" Then
            x = 1
        Else
            x = .Range("A1").End(xlDown).Row
        End If

        With .Range("a" & x, Cells(r, c))
            .AutoFilter field:=5, Criteria1:="10"
            On Error Resume Next
            '.Offset(1, 0).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).ClearContents 'to clear the cells

            '.Offset(1, 0).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).EntireRow.Delete 'to delete entire row
            On Error GoTo 0
            .AutoFilter


        End With
    End With

End Sub
 
Upvote 0
Thnx Mark for the reply,

if i want to learn very details about find from basics to advanced. which online book or sites will i get ?
 
Upvote 0

Forum statistics

Threads
1,215,564
Messages
6,125,579
Members
449,237
Latest member
Chase S

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