prezftb09

New Member
Joined
Mar 5, 2018
Messages
8
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
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
The standard way is to create a case label like ErrorHandler: at the end of the sub... then you can have your message box there... with On Error Go To ErrorHandler

Code:
Sub AAA()
    On Error Go To ErrorHandler
    ...

ErrorHandler:
    MsgBox ...
End Sub
 
Last edited:
Upvote 0
What error(s) are you getting?
 
Upvote 0
Depending on what errors you're getting changing this
Code:
Dim data_end_row_number As Integer
to
Code:
Dim data_end_row_number As Long
might help
 
Upvote 0

Forum statistics

Threads
1,215,640
Messages
6,125,976
Members
449,276
Latest member
surendra75

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top