I have the below formula. I need an On Error message prior to this line of code "data_end_row_number = ws.Range("A1").End(xlDown).Row" that will pop up a msg box that says some information for why error is happening. After msgbox, i just want macro to end. I cant trying different methods but I keep getting errors.
Sub AddtoDelete()
'source worksheet
Dim ws As Worksheet
Set ws = Application.Worksheets("Data") ' set you source worksheet here
Dim data_end_row_number As Integer
data_end_row_number = ws.Range("A1").End(xlDown).Row
'enable filter
ws.Range("A1:AO1").AutoFilter Field:=22, Criteria1:="YES", VisibleDropDown:=True
On Error Resume Next
ws.Range("Y2:AO" & data_end_row_number).SpecialCells(xlCellTypeVisible).copy
On Error GoTo 0
Sheets("Delete").Activate
'Select the target range
Range("A2").Select
'Paste in the target destination
On Error Resume Next
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
On Error GoTo 0
Range("A2").Select
End Sub
Sub AddtoDelete()
'source worksheet
Dim ws As Worksheet
Set ws = Application.Worksheets("Data") ' set you source worksheet here
Dim data_end_row_number As Integer
data_end_row_number = ws.Range("A1").End(xlDown).Row
'enable filter
ws.Range("A1:AO1").AutoFilter Field:=22, Criteria1:="YES", VisibleDropDown:=True
On Error Resume Next
ws.Range("Y2:AO" & data_end_row_number).SpecialCells(xlCellTypeVisible).copy
On Error GoTo 0
Sheets("Delete").Activate
'Select the target range
Range("A2").Select
'Paste in the target destination
On Error Resume Next
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
On Error GoTo 0
Range("A2").Select
End Sub