Error issues

ian0886

New Member
Joined
Dec 10, 2016
Messages
42
Hi Guys,

I'm trying to include error handling in the VBA below. So basically if the file (Workbooks("Pmet_Activity.csv")) doesn't exist, i'd like it to continue running ws(1). Thanks in advance!

Sub BNPAll()


Dim wbMO1 As Workbook, wbMO2 As Workbook
Set wbMO1 = Workbooks("Fx_Activity.csv")
Set wbMO2 = Workbooks("Pmet_Activity.csv")

Dim ws(1 To 2) As Worksheet
Set ws(1) = wbMO1.Sheets("Fx_Activity")
Set ws(2) = wbMO2.Sheets("Pmet_Activity")

On Error Resume Next
ws(2).Activate
ws(2).Range("A1").CurrentRegion.Offset(1, 0).Copy

ws(1).Activate 'run this line if ws2 doesn't exist
ws(1).Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteAll, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Call BNPSort
wbMO1.Close False
wbMO2.Close False
End Sub

Ian
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,624
Latest member
gregg777

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