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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Damon Ostrander

MrExcel MVP
Joined
Feb 17, 2002
Messages
4,239
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
 

Forum statistics

Threads
1,144,148
Messages
5,722,786
Members
422,458
Latest member
Muirzy

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
Top