PDA

View Full Version : [SOLVED] if not found record after 1st criterial in Advanced Filter - then move to next if



mokie
03-01-2018, 09:33 PM
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

mana
03-04-2018, 01:40 AM
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