Dynamic INDIRECT value from another sheet

tezza

Active Member
Joined
Sep 10, 2006
Messages
375
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
  2. Web
Hi,

I'm trying to grab data from another sheet but not getting the expect result.

The name of the sheet depends on the value in cell V1

=INDIRECT("'WK "&V1&"'!"&C2)

In this case, V1 = 29, then it should go to sheet 'WK 29'!C2 but I get a #REF error

The forumla help thinks I'm trying to read from WK 29 and the value in the current sheet at C2, (='WK 29'!45) which is wrong.

If I change it slightly to

=INDIRECT("'WK "&V1&"'!C2") then it works, however C2 become fixed, which won't drag down to D2, E2 etc.

Please help :)
 
What if you press F9?
Also, make sure that your value in cell V1 and your sheet name do not have any extra spaces or special characters in them.

It seems to work for me. Here is the sample data on my "WK 29" sheet:
View attachment 99304

And if I place the formula in cell C2 of my other sheet and drag down/across, this is what I see:
View attachment 99305
Ahh my mistake, I was testing it in Col R to see if it matches what's currently there. Yes it works great, thank you.

What's the best way to now add four sheets together, I initially was going with V1 + 1.... V1 + 2.... and V1 + 3 or would I have to set V to say 39, then W,X,Y to 40, 41, 42 and put a formula like below adding them all as seperate values:?

Excel Formula:
=OFFSET(INDIRECT("'WK "&$V$1&"'!C2"),ROW()-2,COLUMN()-3)+OFFSET(INDIRECT("'WK "&$W$1&"'!C2"),ROW()-2,COLUMN()-3)+OFFSET(INDIRECT("'WK "&$X$1&"'!C2"),ROW()-2,COLUMN()-3)+OFFSET(INDIRECT("'WK "&$Y$1&"'!C2"),ROW()-2,COLUMN()-3)
 
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Quite frankly, INDIRECT and OFFSET functions are not optimal. Besides this formula getting really long, both INDIRECT and OFFSET are volatile functions which can slow your workbook down (see: Excel Recalculation).

If it were me, I think I would rather use VBA code to create and apply the formula that is needed for each cell.
Not sure if that is something you would consider. If so, we would need to know the rules for what sheets/ranges to include and when to run it (if you want it to run automatically instead of running it manually).
 
Upvote 0
Quite frankly, INDIRECT and OFFSET functions are not optimal. Besides this formula getting really long, both INDIRECT and OFFSET are volatile functions which can slow your workbook down (see: Excel Recalculation).

If it were me, I think I would rather use VBA code to create and apply the formula that is needed for each cell.
Not sure if that is something you would consider. If so, we would need to know the rules for what sheets/ranges to include and when to run it (if you want it to run automatically instead of running it manually).
I'll get back to you on that one and give you a better visual of what I'm doing.
 
Upvote 0
What I have here is an example of what I'm using.

Sheets WK 29 to WK 32 look that same but have hours manually added into cells C2 - J down to bottom of list.

Inter Wks 29 - 32 looks for Name 1 and hours in WK 29 - WK 32 and sums the number of hours over the four weeks, and so on for all names.

Currently, it might not be pretty, but it works, however, every month the users have to manually change the formulas to add 4 weeks, eg:

Excel Formula:
=SUMIFS('WK 29'!C$2:C$96,'WK 29'!$A$2:$A$96,$A2)+SUMIFS('WK 30'!C$2:C$96,'WK 30'!$A$2:$A$96,$A2)+SUMIFS('WK 31'!C$2:C$96,'WK 31'!$A$2:$A$96,$A2)+SUMIFS('WK 32'!C$2:C$96,'WK 32'!$A$2:$A$96,$A2)

WK numbers change to

Excel Formula:
=SUMIFS('WK 33'!C$2:C$96,'WK 33'!$A$2:$A$96,$A2)+SUMIFS('WK 34'!C$2:C$96,'WK 34'!$A$2:$A$96,$A2)+SUMIFS('WK 35'!C$2:C$96,'WK 35'!$A$2:$A$96,$A2)+SUMIFS('WK 36'!C$2:C$96,'WK 36'!$A$2:$A$96,$A2)

C$96 is just a random row I added to allow for addional names to be added but I know it can be done better.

Not many staff are excel savvy so I end up having to update multiple departments every month.

How can I make the 'InterWks 29 - 32' automatically look for sheets 'WK 29 - WK 32' ?

I'm open to options here.

Book1
ABCDEFGHIJ
1AreaASP Weeks 29 - 32NormalWeekendOfficeSp TaskAnnual LeaveSickSt MilesOn Call
27262Name 100900000
317934Name 2266000000
417939Name 300000000
517942Name 499000000
617965Name 500400000
717967Name 6001600000
818033Name 7130000000
918139Name 8001200000
1020038Name 9139000000
1121483Name 1050000000
1222349Name 11140000000
13
14
15
Inter Wks 29 - 32
Cell Formulas
RangeFormula
C2:C12C2=SUMIFS('WK 29'!C$2:C$96,'WK 29'!$A$2:$A$96,$A2)+SUMIFS('WK 30'!C$2:C$96,'WK 30'!$A$2:$A$96,$A2)+SUMIFS('WK 31'!C$2:C$96,'WK 31'!$A$2:$A$96,$A2)+SUMIFS('WK 32'!C$2:C$96,'WK 32'!$A$2:$A$96,$A2)+D2
D2:J12D2=SUMIFS('WK 29'!D$2:D$96,'WK 29'!$A$2:$A$96,$A2)+SUMIFS('WK 30'!D$2:D$96,'WK 30'!$A$2:$A$96,$A2)+SUMIFS('WK 31'!D$2:D$96,'WK 31'!$A$2:$A$96,$A2)+SUMIFS('WK 32'!D$2:D$96,'WK 32'!$A$2:$A$96,$A2)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
C2:J15,L2:L15Cell Value=0textNO
 
Upvote 0
If it were me, I would probably create an Access Database to do this. What you really have is a "relational database" (a bunch of related data), and Access (or SQL) handle it SO much better than Excel, as they are relational database programs by nature, and Excel is not. But of course you need to understand relational database theory and Access in order to design the database properly.

Otherwise, I would recommend changing the structure of your data to make it easier to work with, i.e. have one large data sheet where ALL the data gets entered, like this:
1695908478670.png


And then you can easily write SUMIF formulas to include totals for just the week numbers you want (i.e. >=29 and <=32).
 
Upvote 0
If it were me, I would probably create an Access Database to do this. What you really have is a "relational database" (a bunch of related data), and Access (or SQL) handle it SO much better than Excel, as they are relational database programs by nature, and Excel is not. But of course you need to understand relational database theory and Access in order to design the database properly.

Otherwise, I would recommend changing the structure of your data to make it easier to work with, i.e. have one large data sheet where ALL the data gets entered, like this:
View attachment 99456

And then you can easily write SUMIF formulas to include totals for just the week numbers you want (i.e. >=29 and <=32).
Interesting approach. I'll look more into this and see if it's a viable option for the smaller groups.

The main sheet would likely have in excess of 1000+ rows per week.

The data is generated as a csv file per week, which then runs a explicit macro from another workbook to make it like above before entering any hours.
 
Upvote 0

Forum statistics

Threads
1,215,077
Messages
6,122,995
Members
449,094
Latest member
masterms

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