Using Sheet references in formula/VBA

mickyh

New Member
Joined
Jul 10, 2012
Messages
38
Office Version
  1. 365
Platform
  1. Windows
Good Morning.

I would like some help, please.
I have a workbook where amongst other things I have a sheet that collates information from up to 25 other sheets. It's a simple formula but it reoccurs about 500 times and whenever I make a change I have to rewrite the formula for each sheet. Is it possible to use a cell reference instead of the sheet name? either by formula or VBA?
The sheets are named 1 - 25 so, for example, on the sheet that collates the information the formula in cell B4 is as follows
Excel Formula:
=IF('1'!C8>=1,1,"")
and the formula in H82 is
Excel Formula:
=IF('1'!I91>=1,1,"")
with most of the cells in between following the same pattern. sheet 2 starts in cell J4, Sheet 3 in R4, and so on.
I'd like to replace the sheet name with a cell reference that contains the cell name if that is possible. I'd like to be able to use B1 to contain the name of sheet 1, J1 to contain the name of Sheet 2, and so on so that referring to those cells replaces the sheet name in my formula.
This might not even be possible so thanks for looking, if you have any suggestions then they will be gratefully received.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
I thought I might have a solution, but then I read this:
sheet 2 starts in cell J4, Sheet 3 in R4, and so on.
and realised it's not as straight forward as I had first thought. Do you think you could please show what you're after using the XL2BB addin? XL2BB - Excel Range to BBCode
It would help a lot if I can visualise what you're hoping to accomplish.
 
Upvote 0
Actually, without yet knowing exactly what it is that you're after, I wonder if the INDIRECT function might be useful.

ScrollText_Scores_Test (version 1).xlsb
ABCDEFG
1Sheet NameCell ReferenceCell Value
21E410
32F420Sample Data Set
43G430102030
1
Cell Formulas
RangeFormula
C2:C4C2=INDIRECT("'"&A2&"'!"&B2)



Basically, I created three worksheets - entitled "1'", "2", and "3". In cells E4 to G4 on all three sheets, I put the same data set: 10, 20, and 30.
Using the INDIRECT formula in Column C, you can access the value on the designated sheet (see Column A) and designated cell (see Column B).
Would that help?
 
Upvote 0
Solution
Hi Dan
Thanks for getting back to me so quickly, I was having trouble with xl2bb but I think I have sorted it now. (I have replicated the page on a separate sheet)
Sample weekly allocation.xlsx
ABCDEFGHIJKLMNOPQRSTUVWX
1W/C 12/SepW/C 12/SepW/C 12/Sep
2Current Jobs Mick Employee 2Employee 3
3Construction M TWTFSSM TWTFSSM TWTFSS
45889 St Lukes Doors                     
56687 Bowerhill Rooflights Phase 2                     
66694 Devizes School MSH                     
7Soverign Kitchens and Bathrooms.                      
86777 18 Elm Park                      
96750 21 Glebe Road                      
105933 Tanglin Farm Air BnB                     
11                      
126718 LPA Fencing                     
136729 9 Thornhill                     
146773 Watermoor Road                     
15                      
16Snagging Projects                      
176661 The Ridge                     
186685 52 Furze Close                     
196729 Thornhill Close                      
20                      
215994 5 Shelly Avenue                     
226552 Spratts Barn Cresent                     
236694 Devizes School MSH                     
24Instadoor                     
25Maintenance/Minor Works                     
26Office/Admin                     
27Training/College                     
28Holiday/Unpaid Leave/Sick Leave                     
Matrix
Cell Formulas
RangeFormula
A4:A28A4='1'!A8
B4:H28,R4:X28,J4:P28B4=IF('1'!C8>0,1,"")
Cells with Conditional Formatting
CellConditionCell FormatStop If True
R4:X58Other TypeIcon setNO
J4:P58Other TypeIcon setNO
B4:H58Other TypeIcon setNO


I will give the indirect function a try although I have tried it previously and for some reason, it didn't seem to do what I wanted!.

Thanks again
 
Upvote 0
Ok - thank you for that. That helps a bit in clarifying things, but I think I need to look at it tomorrow before work to wrap my head around it properly, if you've not solved it before then.
I'm inclined to suggest a VBA solution, because otherwise that seems like a lot of formulas in play.
 
Upvote 0
Thanks, Dan
Your suggestion of indirect works and a little bit more research led me to use it with the Cell function which allows me to make the reference to the cells relative. this is what I've ended up with in B4
Excel Formula:
=(INDIRECT("'"&$B$1&"'!"&CELL("address",C8)))

Thanks again
 
Upvote 0
You're welcome. Another function that might be useful is the OFFSET function.
 
Upvote 0

Forum statistics

Threads
1,215,825
Messages
6,127,111
Members
449,359
Latest member
michael2

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