Consulting

Results 1 to 2 of 2

Thread: if not found record after 1st criterial in Advanced Filter - then move to next if

  1. #1

    if not found record after 1st criterial in Advanced Filter - then move to next if

    Hello I'm looking for help in statement if/else I'd like to found in table in column 9 in filtr on string "looking_for_record_in_this_case" But firstly I matching in column 20 those sign "="
    If after matching string "looking_for_record_in_this_case" Any record doesn't exist I'd like to move to next statement.

    thanks in advanced
    sub asdfg




    Dim asdfg As Range
    Dim iLastRow As Long
    iLastRow = ws.Cells(Rows.Count, "B").End(xlUp).Row






    Set asdfg = Range("$A$3:$U$" & iLastRow)






    ' if macro found in filtr "looking_for_record_in_this_case" then i need to check if exist any record
    ' if not exist then skip those statement and move to next statement if/else






    If asdfg.AutoFilter(field:=9, Criteria1:="looking_for_record_in_this_case") = True Then
    asdfg.AutoFilter field:=20, Criteria1:="="


    asdfg.AutoFilter field:=9, Criteria1:="looking_for_record_in_this_case"
    Exit Sub






    MsgBox "Not found", vbCritical, "error"
    'Exit Sub
    Else
    If asdfg = False Then
    'asdfg.ShowAllData
    asdfg.AutoFilter field:=20, Criteria1:="="
    MsgBox "I'm not found any record in filtr on column 9 - looking_for_record_in_this_case!! - and it filtred by only column 20"


    End If
    End If
    end sub


  2. #2
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    Sub test()
    
        With Cells(1).CurrentRegion
            .AutoFilter
            .AutoFilter 9, "looking_for_record_in_this_case"
            If .Columns(1).SpecialCells(xlCellTypeVisible).Count = 1 Then
                .AutoFilter
            End If
            .AutoFilter 20, "="
        End With
    
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •