I am running a macro where it filters based on a number that the user has entered. It then takes that number and filters a list based on that value. I need a validation where if a user put in a number that is not on the list it will exit the macro. I think I am close but I am new to VBA so I keep getting stuck. Any help would be awesome!
Thanks!
'Filter based on user entry
Sheets("New Revision ").Select
part = Range("B4").Value
Sheets("PN_List").Select
Columns("D:E").Select
Selection.EntireColumn.Hidden = False
ActiveSheet.Range("$A$1:$K$3000").AutoFilter Field:=1, Criteria1:=part
If ActiveSheet.Range("$A$1:$K$3000").AutoFilter Field=1, Criteria1="" Then
MsgBox "Part number not found please try again.", vbOKOnly + vbExclamation, "Entry Error"
Exit Sub
End If
Try this out:
Edit: you can still filter if you want that. Maybe a good place to do that is in an
Else
clause ofIf Not Found
.