keep lookup sheet name static for renaming sheets.

ferret

New Member
Joined
Oct 15, 2002
Messages
25
hey everyone.
my problem is this....
i have a sheet in a workbook looking up data on another sheet called "this week". but the following week i want to change the "this week" sheet to have the title as the week no. (11), and create a new "this week" sheet. The problem is that the sheet with the lookups now looks up the data in the "11" sheet instead of the "this week" sheet. Is there any way to make the lookup sheet static, the way you can make a cell reference static with the $ symbol?
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Hi ferret,

One way that immediately comes to mind is to use a VBA user-defined function (UDF) to do your lookup (e.g., if you are using VLookup, call it from inside the UDF), and don't pass the table range as an argument but hard-wire it in the UDF. When you rename the sheet, VBA remains unchanged and still looks for a worksheet named "this week".

Here's a specific example. Suppose you are currently using the formula:

=VLOOKUP(B4,'this week'!$D2:$Q22,3,FALSE)

Replace this call with the UDF call

=MyVlookup(B4,3,FALSE)

where MyVlookup is the following UDF:

Function MyVlookup(Lval As Variant, Col As Integer, range_lookup As Boolean) As Variant
Dim Table As Range
Set Table = Worksheets("this week").[D2:A22]

MyVlookup = Application.WorksheetFunction.Vlookup(Lval,Table,Col,range_lookup)

End Function
 
Upvote 0

Forum statistics

Threads
1,214,936
Messages
6,122,340
Members
449,079
Latest member
rocketslinger

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