I currently have the sub-Macro below which filters for Columns A and B (for Strings Asset and SN), and then copies the value. What I'm trying to figure out is how do I set it so that if no results are found for either, the macro would generate an error instead of crashing/copying just the title headers.
What I need to Macro to do is if Asset and/or SN or not found in the filter, than generate error "Asset# not found" or "SN# not found". How can I do that?
VBA Code:
Sub filter()
ws1.Activate
' Turn off AutoFilter if it's on
If ws1.AutoFilterMode Then
ws1.AutoFilterMode = False
End If
' Turn on AutoFilter
ws1.Range("A1").AutoFilter ' Assumes your data starts from A1; adjust as necessary
' Apply filters based on Asset and SN
ws1.Range("A:A").AutoFilter Field:=1, Criteria1:=Asset
ws1.Range("B:B").AutoFilter Field:=2, Criteria1:=SN
' Find the last non-empty row in column A
ws1.Range("A" & Cells.Rows.Count).End(xlUp).Activate
CalFreq = ActiveCell.Offset(0, 9)
PM1Freq = ActiveCell.Offset(0, 12)
PM2Freq = ActiveCell.Offset(0, 15)
End Sub
What I need to Macro to do is if Asset and/or SN or not found in the filter, than generate error "Asset# not found" or "SN# not found". How can I do that?