Multiple sheet name references - excel

I have 30 sheets in one workbook. In Sheet1, how can I use a formula to return sheet names of the other 29 sheets within the same workbook? My preference is not to use udf or vba.
This is the formula I am using to return the name of the active worksheet:
=MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,25)
I modified the formula to this:
=MID(CELL("filename",'Sheet 1'!A1),FIND("]",CELL("filename",'Sheet 1'!A1))+1,25)
but when I use this formula, I get a message box titled "Update Values: Sheet 1" - essentially prompting me to select the workbook. Once I select the workbook, I am prompted to select the sheet. Once I do that, the formula returns #N/A. I tried resaving the workbook, but same result.

You could use an obscure XL4 function, GET.WORKBOOK to return a list of the sheets in the active workbook instead as follows:
Define a range name called "WorksheetNameList" using the formula:
=GET.WORKBOOK(1)
Then, in your Sheet1 use the formula in cell A1:
=MID(INDEX(WorksheetNameList,ROW(A1)),FIND("]",INDEX(WorksheetNameList,ROW(A1)))+1,32)
and then drag the formula down the rows until you hit row 30 (or you obtain a #REF!).
I would not normally recommend using XL4 functions since they could disappear at any time with new Excel releases, but they are used here based on the restriction of your question.
If you'd like more information on what else GET.WORKBOOK can return, please have a look at the help file which is located at http://www.microsoft.com/downloads/details.aspx?FamilyID=c09bf7f7-d30e-4ce9-8930-5d03748ca5cd

Related

Using VBA, hide multiple rows based on a single cell that is empty but has a link to another worksheet code

I have a workbook that uses data from one worksheet to fill in cells of another worksheet.
I am having problems finding or building a VBA that will automatically hide several rows base on a cell that has a "link" to a cell in another worksheet. Need for several sections.
Worksheet 1 - is a Data page
Worksheet 2 - is a Display page
For example:
Worksheet "Program Data"
Program Data
Worksheet 2 is the "Production Schedule"
Production Schedule
On worksheet 2 "Production Schedule"
I want to automatically hide rows 13:20 if Cell E15 is blank (but it has the "='Program Data'!E16" reference in it.)
and additionally
I want to automatically hide rows 21:28 if Cell E21 is blank (but it has the "='Program Data'!E26" reference in it.)
and so on...... for multiple sections of the worksheet "Production Schedule"... Not all sections have the same number of rows to hide if the indicated cell is blank or has the "link" to Program Data worksheet.
I also would like for it to unhide rows if data is entered into the "reference cell" on the data sheet at a later time..
I know this is asking a lot, so any advice would be greatly appreciated.
Here's a simple VBA script that worked fine for me:
I created two Excel sheets: "Sheet1" & "Sheet2"
In Sheet2, cell:A1, I made a reference to a cell on Sheet1
By default, Excel cell reference formulas (like the one above) will return 0 if the referenced cell is blank. You can change this easily with an =if statement if desired, e.g.:
=IF(Sheet1!A1<>"",Sheet1!A1,"")
For the VBA script, I let the reference cell return the default value "0"
Now, if I input "bob" into the referenced cell and run the VBA script again, x returns "bob"
Okay, now here is the simple script which worked fine when I tested it:
Note that I added "Calculate" which will calculate the formulas in the workbook (including our formula reference cell) to ensure the returned value is correct.
Of course, you can modify this to check other cells, hide other rows, etc. Including the Else portion in your VBA IF statement will also "unhide" rows if the reference value is populated or said another way, doesn't equal "0" by setting the hidden property to false.

List Sheet Names Without Macro or Excel 4 Functions

I am trying to list all sheets in an Excel workbook with a method that works for macro-free workbooks such as .xlsx files.
I am aware of the following options although both require the workbook to be saved in a file format that allows macros:
Method 1: Excel 4 Function
See this answer I posted.
Method 2: VBA
See this answer posted by another user.
Is there any option to list all sheets? If not is there any formula that names any sheet beyond the sheet containing the formula?
If you have the flexibility, you can use the formula from #urdearboy in e.g. A1 on each sheet, then use a 3D reference to collect them together e.g. =TEXTJOIN(CHAR(10), FALSE,'FirstSheet:LastSheet'!A1) and then extract from the string.
It's a big kludge but it does work. (But at the moment I'm happy with all the sheets listed in 1 cell; A1 contains sheetname + description)
Caveat - FirstSheet & LastSheet must obviously span the range of sheets to be listed, and if they get moved around, the 3D reference may be inappropriate or break
This is a great question in the context of building macro-free workbooks.
To make an contents list of sheetnames, the formula from #urdearboy can be pasted in cell A1 of each sheet being indexed:
=MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,255)
If cell A1 of each of these sheets is made a named range, using foo_1, foo_2, foo_3 etc as the names, the index is simply =foo_1 in the first cell of the contents range, or better =indirect("foo_", 1), with 1 replaced by a cell reference to a number sequence.
The content list stays up-to-date, even if the sheet names are changed.

Can I use one formula for several sheets?

I have a workbook that currently have 20 sheets and it grows with about 3 sheets per day.
All sheets use the same formulas in columns H-L.
But sometimes I find errors in the formulas or need to ad a condition to it and then I need to update all sheets formulas with the same formula. And that is the problem.
Can I have the formula in one cell somewhere and in each column just reference to this formula so that if I change the formula in this cell it will change in all places?
In each sheet I need the formula to "fill down" about 2300 rows.
In sheet1
A1
=A1+B1
In sheet2
A1
='sheet1'!A1 // will calculate A1+B1
Anyone know of a way to do this?
If all sheets have the same structure, you can use a 3D selection to change a formula in the same cell on all sheets.
For example, if your workbook has sheets 1 to 10, select cell B1 in Sheet1, then hold down the Shift key and click Sheet10. Now all cells B1 in all sheets from Sheet1 to Sheet10 are selected, no matter what the sheet name is.
Enter a formula like =A1+A2 and hit Enter. Click any sheet and check the result. B1 will have that formula in each of the sheets.
Now go back to Sheet1, select B1, hold Shift and click Sheet10. Change the formula to =A1*A2 (multiply instead of add) and hit Enter. Copy the formula down.
Check the other sheets and see that the same formula has been applied and copied down on all other sheets.
With this technique, you can select the same cell in all sheets of the workbook and change the formula in all sheets with just one edit. Of course, it only works if all sheets in the selection have the same data structure.
Edit after comment: You could use the first sheet as the Formula Master sheet, and just need to remember that if you want to change a formula, you first have to use a 3D selection. Other than that, Excel does not offer formula replication in the way you describe. A reference to a cell will always return the cell's value, not its formula.
You could create a UDF (user defined function) in VBA for your goal:
Press Alt+F11, right click on your project in the project explorer and select Insert --> Module. Paste the code below:
Function ExecuteFormula(ByVal Target As Range)
On Error Resume Next
ExecuteFormula = Evaluate(Target.Formula)
End Function
Now you can use the ExecuteFormula() like every other function. If you want to enter the formula in your master sheet as a string "=A1+B1" just replace the 3rd line with:
ExecuteFormula = Evaluate(Target.Value)
I hope this helps.

Dynamic sheet name in Excel

I can reference a sheet name from another sheet
='Sheet1'!A1
How can I do thus with formula (not VBA or Python, sadly) to find out the name of the sheet dynamically (ie without knowing the name sheet)? Just to be clear I'm after the sheet names/ tab names at the bottom of the window, not the worksheet name
I've got number of spread sheets with a number of sheets (all named differently) and I was looking for a formula that will work with all. One size fits all , if you will.
Try this:
In the Name Manager create a Name using this formula:
=REPLACE(GET.WORKBOOK(1),1,FIND("]",GET.WORKBOOK(1)),"")
Then in your worksheet, use INDEX function to retrieve sheet names like this:
=INDEX(SheetList,1)
To List all sheets then select the target range and enter SheetList as array formula using Ctrl+Shift+Enter.
{=SheetList}

Link two sheets in excel - So a row added in one gets added in the second

I'd like to know if it is possible to link two sheets so that if I add a row in one sheet it autmatically gets added to the second sheet.
Thanks.
Not exactly -- I'm pretty sure you can't link an entire sheet. But you could use formulas with cell references, e.g. =Sheet2!B2 refers to cell B2 from Sheet2.
You could also try the vlookup() formula function. If you have a table defined somewhere in the workbook, you can use this function to return the value from one column of the table based on the supplied value from another column in the table.
You can "Group" sheets together by holding down CTRL and selecting the tabs of the sheets to be grouped. Adding and deleting rows and columns would result in the same treatment over all the selected sheets. But this is temporary and is lost as soon as another sheet is selected or the file is closed.
For a longer term entanglement, you would need VBA code.

Resources