Set a network path in VBA for excel formulas

ItalianPlatinum

Well-known Member
Joined
Mar 23, 2017
Messages
857
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello,
I have multiple columns that reference the same network path. At times I may need to change that path but i dont want to go into my VBA every time and modify all the lines of code that use that path. I am looking for a way to set that path once then its used throughout the rest of the code. would someone be able to assist? here is my line of code i have to XXXX out the path due to confidential names in there.

VBA Code:
Sub CopyFormulas()
Dim rws As Long
Dim UsdRws As Long
Dim LastRow As Long

'paste formulas down in Compare
With Sheets("Calc")
    .Unprotect
    .Range("D1:L" & Cells(Rows.Count, "A").End(xlUp).Row).Formula = "='\\East.ad.XXXXX.com\amer\XX\share\Client\UT\XXXX\[Review.xlsb]Rate!D8"
    .Range("M1:M" & Cells(Rows.Count, "A").End(xlUp).Row).Formula = "='\\East.ad.XXXXX.com\amer\XX\share\Client\UT\XXXX\[Review.xlsb]Dist'!K8"
    .Range("N1:N" & Cells(Rows.Count, "A").End(xlUp).Row).Formula = "='\\East.ad.XXXXX.com\amer\XX\share\Client\UT\XXXX\[Review.xlsb]Dist'!O8"
    .Range("O1:O" & Cells(Rows.Count, "A").End(xlUp).Row).Formula = "='\\East.ad.XXXXX.com\amer\XX\share\Client\UT\XXXX\[Review.xlsb]Dist'!S8"
    .Range("S1:S" & Cells(Rows.Count, "A").End(xlUp).Row).Formula = "='\\East.ad.XXXXX.com\amer\XX\share\Client\UT\XXXX\[Review.xlsb]Dist'!T8"
    .Range("D1:O21") = .Range("D1:O21").Value
End With

With Workbooks("Daily Calc -- Sw and Expenses.xlsm").Sheets("Calc")
.Range("Q2").Formula = "=iferror(VLOOKUP(Q24,'\\East.ad.XXXXX.com\amer\XX\share\Client\UT\XXXX\[Review.xlsb]Distrib!$C$9:$W$50000,23,FALSE),0)"
.Range("Q27").Formula = "=IF(SUMPRODUCT(('\\East.ad.XXXXX.com\amer\XX\share\Client\UT\XXXX\[Review.xlsb]Distrib!$G$8:$G$500000=""B"")*(MID('\\East.ad.XXXXX.com\amer\XX\share\Client\UT\XXXX\[Review.xlsb]Distrib!$C$8:$C$500000,7,2)=""VR"")*('\\East.ad.XXXXX.com\amer\XX\share\Client\UT\XXXX\[Review.xlsb]Distrib!$H$8:$H$500000<>""B"")),""Yes"",""No"")"
End With

'protect and add filtering ability
With Sheets("Calc")
    .Protect
End With
End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Put the UNC path in a cell or hidden sheet you can edit

Code:
public gvNetDir

gvNetDir = range("AB1").value       'aka:  \\East.ad.XXXXX.com\amer\XX\share\Client\UT\XXXX\

i keep other folder paths nearby like in AB2, AB3 , etc, so i can swap out.
 
Upvote 0
that crossed my mind just I have many users using this file, not super comfortable with that approach. i have the vba PW protected.
 
Upvote 0
i actually found a way to self-service see below if anyone ever wanted to know how

1694621215854.png
 

Attachments

  • 1694621148383.png
    1694621148383.png
    27.1 KB · Views: 13
Upvote 0
Solution

Forum statistics

Threads
1,223,896
Messages
6,175,259
Members
452,626
Latest member
huntinghunter

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