some On Error help

largeselection

Active Member
Joined
Aug 4, 2008
Messages
353
I have some code which basically consolidates all worksheets from a workbook into the first sheet. It has on error resume next so it can continue the code after consolidating. I need to add an error messagebox that appears if the code can't find the correct reference file open. How can I add this? I've tried a couple different constructions and none seem to work.

So I want a messagebox to say can't find reference and then exit the sub since it will mess up the file if it can't find that file. I've tried putting in an on error goto error1 which is a messagebox and exit sub, but then it just does that all the time.

Here is some of the code:
Code:
.
.
.
Dim J As Integer
Windows("Reference.xls").Activate
On Error Resume Next
Sheets(1).Select
For J = 2 To Sheets.Count
Sheets(J).Activate
Range("A1").Select
Selection.CurrentRegion.Select
Selection.Offset(4, 0).Resize(Selection.Rows.Count - 4).Select
Selection.Copy Destination:=Sheets(1).Range("B1048576").End(xlUp).Offset(1, -1)
 
Next
.
.
.
 

Some videos you may like

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

Watch MrExcel Video

Forum statistics

Threads
1,127,204
Messages
5,623,352
Members
415,969
Latest member
Rey99

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
Top