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.
Related
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.
In a worksheet I have a column of references to cells in unique workbooks, e.g. in cell A1:
='Filepath[Workbook1.xlsm]Sheet1'!$A$1
In other columns I want to pull values from other cells in other sheets of each of those same workbooks, e.g. 'Filepath[Workbook1.xlsm]Sheet2'!$B$2
However, I do not want to have to manually copy/paste the filenames into the new columns and then in each of them change the formula to Sheet2'!$B$2
So what I did was write an INDIRECT formula, e.g. =INDIRECT(MID(FORMULATEXT(A1),2,FIND("]",FORMULATEXT(A1))-1)&"Sheet2'!$B$2")
However, as I've found from other posts, there is a limitation of the INDIRECT function that the file being referenced must be open, otherwise it REFs out.
Is there a way in VBA (or just Excel) to circumvent this?
I’m very new to VBA, not really sure where to start. I have two separate workbooks saved in the same folder. What I am looking for is when column A is populated in workbook 1;
I want a macro that searches for that number in workbook 2 column C. If a match is found then I want the corresponding value from column F in workbook 2 to be copied onto column I in workbook 1:
If a match is not found just leave the cell blank.
If more than one match is found, use the greatest number.
Sometimes workbook 1 has multiple pages as well.
Workbook 2 won't be opened by the user, they will just populate the data in workbook 1 and the macro runs automatically if data in column A changes.
Any help is appreciated.
I'm not sure you need VBA here, but I'm brand new to VBA. This is what I would use, and I'm sure someone can convert this to VBA. For reference, I'm calling your workbooks Book1 & Book2. In Book2 (the one you want the result in) use this formula:
=IF(MAX(IF([Book1]Sheet1!$C$2:$C$20000=A26,[Book1]Sheet1!$F$2:$F$20000))=0,"",(MAX(IF([Book1]Sheet1!$ C$2:$C$20000=A26,[Book1]Sheet1!$F$2:$F$20000))))
To make this an array formula, go back to the cell with your formula, hit F2 & then CTRL+SHIFT+ENTER, and it will put brackets around your formula to make it look like this:
{=IF(MAX(IF([Book1]Sheet1!$C$2:$C$20000=A26,[Book1]Sheet1!$F$2:$F$20000))=0,"",(MAX(IF([Book1]Sheet1!$ C$2:$C$20000=A26,[Book1]Sheet1!$F$2:$F$20000))))}
You can then drag that formula down or fill down that formula.
Note: $C$2:$C20000 & $F2:$F20000 is assuming that your part numbers & prices or whatever they are start on row 2, and there are less than 20000 rows, if it is more, just replace the 20000 to however high you need. The A26, appears to my old eyes to be the first cell in which you are typing in the part numbers which correspond to Sheet1 column C.
Hello I am trying to use countif to add up how many cells have January in. For example I have 40 worksheets and I need to find out how many of them contain january in the date in cell C3 on all of the sheets. and put the answer in another sheet.
OPTION 1) Formula Method
1) Write out a list of all the names of your sheets in a column.
2) On the "Formulas" ribbon, select Define Name.
3) Give it a name in the top box, ie. SHEETNAMES
Then use this formula:
=SUMPRODUCT(COUNTIF((INDIRECT("'"&SHEETNAMES&"'!C11")),"Completed"))
I would have thought the formula for your original question would have been very similar but it keeps showing up as an error. I have been using the following:
=SUMPRODUCT(--(MONTH(INDIRECT("'"&SHEETNAMES&"'!C3"))=1))
You can use a 3-D formula, but unfortunately, the only formulas that allow 3-D references are mathematical functions that don't have much in the way of logic (no IFs, ANDs, etc.). If you restructure your workbook a little bit to, say, add IF(C3="January",1,0) in Z3 on each sheet, then you can do SUM(Sheet2:Sheet40!Z3) on your summary sheet.
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