VBA code that references another directory if one does not work

willow1985

Well-known Member
Joined
Jul 24, 2019
Messages
888
Office Version
  1. 365
Platform
  1. Windows
I have a spreadsheet that contains a macro that when run opens various other spreadsheets, grabs their data and closes them. However this main spreadsheet is accessed by multiple users in 2 different ways on a network. Sometimes the drive can appear as X and other times as an address like 190.165.1.22\

Basically what I am looking for is if the macro runs into an error where it cannot find the drive (I am assuming this is the problem because I am getting a Subscript out of range Error) that it will try the 2nd directory (see VBA code)

Any help would be greatly appreciated!

1649947717384.png


VBA Code:
Dim CAPAD As String

Dim CCD As String

Dim CID As String

Dim NCRD As String

Dim ASD As String

Dim CAPAN As String

Dim CCN As String

Dim CIN As String

Dim NCRN As String

Dim ASN As String



CAPAD = Workbooks("Quality Dashboard").Sheets("Graph Data").Range("B15").Value ‘ or Workbooks("Quality Dashboard").Sheets("Graph Data").Range("B22").Value

CCD = Workbooks("Quality Dashboard").Sheets("Graph Data").Range("B16").Value ‘or Workbooks("Quality Dashboard").Sheets("Graph Data").Range("B23").Value

CID = Workbooks("Quality Dashboard").Sheets("Graph Data").Range("B17").Value ‘or Workbooks("Quality Dashboard").Sheets("Graph Data").Range("B24").Value

NCRD = Workbooks("Quality Dashboard").Sheets("Graph Data").Range("B18").Value ‘or Workbooks("Quality Dashboard").Sheets("Graph Data").Range("B25").Value

ASD = Workbooks("Quality Dashboard").Sheets("Graph Data").Range("B19").Value ‘or Workbooks("Quality Dashboard").Sheets("Graph Data").Range("B26").Value



CAPAN = Workbooks("Quality Dashboard").Sheets("Graph Data").Range("B29").Value

CCN = Workbooks("Quality Dashboard").Sheets("Graph Data").Range("B30").Value

CIN = Workbooks("Quality Dashboard").Sheets("Graph Data").Range("B31").Value

NCRN = Workbooks("Quality Dashboard").Sheets("Graph Data").Range("B32").Value

ASN = Workbooks("Quality Dashboard").Sheets("Graph Data").Range("B33").Value

Cell Formulas
RangeFormula
B15B15="\\190.165.1.22\cad\QUALITY\Group\Corrective Actions\CAPA findings\"&B29
B16B16="\\190.165.1.22\cad\QUALITY\Group\Corrective Actions\Customer Concerns - Corrective Action\"&B30
B17B17="\\190.165.1.22\com\Lean Folder\"&B31
B18B18="\\190.165.1.22\cad\QUALITY\Group\Supplier Non-Conformance Reports\"&B32
B19B19="\\190.165.1.22\cad\QUALITY\Group\Audit\"&B33
B22B22="X:\QUALITY\Group\Corrective Actions\CAPA findings\"&B29
B23B23="X:\QUALITY\Group\Corrective Actions\Customer Concerns - Corrective Action\"&B30
B24B24="S:\Lean Folder\"&B31
B25B25="X:\QUALITY\Group\Supplier Non-Conformance Reports\"&B32
B26B26="X:\QUALITY\Group\Audit\"&B33
 
Nice to hear that we managed to help and thanks for the feedback.
 
Upvote 0

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Forum statistics

Threads
1,215,022
Messages
6,122,721
Members
449,093
Latest member
Mnur

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