Declaring a global variable for a string in Excel or VB

stonypaul

Board Regular
Joined
Jan 4, 2008
Messages
86
If I have cause to populate a cell by referencing another cell in another worksheet is it possible to shorten the reference by declaring a global variable with a string value which will replace the common part of the re-occurring reference?
For instance if I have references in two separate cells which are:-

=C:\SUPPORT\Finances\[paid_recd.xls]week1!A1

and

=C:\SUPPORT\Finances\[paid_recd.xls]week1!A2

Is it possible to replace the common part of the string with a variable so you end up with something like:-

=week1_A1

and

=week1_A2

So the variable has a string value of "C:\SUPPORT\Finances\[paid_recd.xls]week1!"

I would prefer to do this in Excel but can cope with VB if necessary, or is there an even better way of doing this altogether?

Thank you
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
You could do this with INDIRECT(), or with a user-defined function written in VBA). But both would be a performance hit. So its best to leave it as it is.

You can shorten the reference (temporarily) by opening the external workbook being referred to - then it will show only the workbook name, not the full path. It will also speed it up if there are heavy links, such as large lookup tables, involved.
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

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