How to find the maximum value in entire Excel workbook - excel

I have an Excel workbook with many sheets (today, about thirty, and growing every day). Each worksheet is named for the date of the data it contains (e.g., 02-10, 02-11, etc.). In cell A2 of each worksheet is a number, and I want to write a formula that looks at cell A2 in every worksheet, and returns the largest one.
I created a list of the current worksheets and named it DayWorksheets, and I attempted to get the value using the formula
{=MAX(INDEX(INDIRECT("'"&DayWorksheets&"'!A2"),0))} (brackets shown to denote array formula).
But the result every time is "10," which is the number in cell A2 of the first worksheet in the named range (and it's not the largest). What am I doing wrong here? I've seen a few other formulas around, the likes of
=VLOOKUP(C1,INDIRECT("Sheet"&MATCH(TRUE,COUNTIF(INDIRECT("Sheet"&ROW(INDIRECT("1:10"))&"!A2:A100"),B1)>0,0)&"!A2:B100"),2,0),
but I don't quite understand the purpose of the countif function in there. Any help would be appreciated.

You can use formula with 3D-reference like this:
=MAX(Sheet1:Sheet30!A2)
Click the cell where you want to enter the function.
Type = (equal sign), enter the name of the function (MAX), and then type
an opening parenthesis.
Click the tab for the first worksheet that you want to reference.
Hold down SHIFT and click the tab for the last worksheet that you
want to reference.
Select the cell or range of cells that you want to reference (A2 in your case).
Complete the formula (add closing parenthesis), and then press ENTER.

Related

Excel - Reference within a reference

I may going up the wrong tree with this.
I have the following formula, that will replace the * with the range of sheets in the workbook, and SUM the values in cell B2 on each of the sheets:
=(SUM('*'!B2)/J2)/100
This works fine, however the formula doesn't retain the '*', it replaces it with the actual range, eg:
=(SUM('Period 1:Period 4'!B2)/J2)/100
So, is it possible to either:
Retain the '*' so that the formula doesn't update, and therefore remains dynamic should I add a new tab.
Add a reference into the reference. The first sheet will always be 'Period 1', however the end sheet will change from month to month, and will be 'Period x', where x is the value in cell J2. Is it possible to reference J2 within =(SUM('Period 1:Period 5'!B2)/J2)/100? =(SUM('Period 1:Period [J2]'!B2)/J2)/100 or something similar?
The only way I know to do this is to create a 'sheet sandwich' with a 'Start' and 'End' sheet then the range is =SUM('Start:End'!B2). New sheets obviously have to be inserted between these to be included.
Note:not my solution, credit belongs to SUM across multiple sheets with variable sheet name question.

Excel, Create a named range from the contents of cells usign cell formulas

I am stuck...
I have a 100 Row sheet with 10 Columns. This list is broken into classes simply by inline headers. I have definitions of the blocks of data under each head, for example:
UNASSOCIATED A2 A19
HOSTS A21 A32
ROOF A34 A100
I compute those ranges as they may change from time to time. I need
first: Define Name of each group by formula
Second: From time to time select the defined group
I am unable to get a formula to work which will allow me to use the "Content" of the cell as opposed to the cell location to define these ranges.
I'm stuck.
Suggestions would be appreciated.
Regards,
RHD
This cannot be done in a cell formula. You'll need to create a macro (VBA) to do this. Essentially, what you need is to grab the value of a cell then use that value as if it were a cell address.
Take a look at the example macro below. If cell A1 contains the characters "B22", then x will become the value of A1 (which is "B22") and "test" will be written to cell B22. This cannot be done in with cell formulas.
Sub test()
Dim x As String
x = Range("A1").Value
Range(x).Value = "test"
End Sub
A good amount of adaptation will been needed to incorporate this technique, and you'll need to play with this a bit. Ping this community to help answer more specific questions as they come up.

Calling the same cell of different worksheets in EXCEL

I have a drop down list (with name of sheets) and based on that value, let's say that I select the Sheet4 as in the image, I want to bring to another sheet the value of that selection, let's say on the cell B8.
I know that this works:
=IF(B1="Sheet1", Sheet1!B8, IF(B1="Sheet2", Sheet2!B8, Sheet3!B8))
That's for just 3 sheets but is there a nicer or more efficient way to do this?
This is in general how all the sheets look like:
Use INDIRECT to construct a valid worksheet and cell reference from text-that-looks-like-a-worksheet-and-cell-reference 1
The indirect takes a string and turns it into a valid reference.
=INDIRECT("'" & B1 & "'!B8")
So in the case above it would create a string "'Sheet4!B8". Then the Indirect will turn it into a valid cell reference.
As Jeeped also pointed out in the comments The B8 reference since it is literal text it will not change if the formula is copied or dragged to another cell.
The B1 which is a cell reference and is relative will change as it is copied or dragged to different cells.
1 as per #Jeeped comment

Using Index Match between two sheets in excel

I have two sheets.
This is the first sheet. Named 3
And this is the second sheet. Named centralizare
I have to write in Sheet2 C5 the number of 'Id garantie' from Sheet1 if the 'Categorie' from Sheet1 is 'Done' (Sheet2 B5) and 'Status 1'from Sheet1 is 'In lucru' (Sheet 2 B4)
I tried this
=COUNT(INDEX('3'!$C$2:$C$99,MATCH(B5,'3'!A2:A99,0)))
but it returns only one number if only the 'Categorie' is Done.
And other method with errors
=MATCH('3'!C2:C99,(centralizare!C5='3'!B2:B96)*(D4='3'!F2:F96),0)
=INDEX('3'!$C$2:$C$99,MATCH(D5,'3'!C2:C99,0))
=COUNT(INDEX('3'!A2:A96, MATCH("In lucru",'3'!E2:E96)))
You could try an array formula with sumproduct:
=SUMPRODUCT(--IFERROR((('3'!A2:A5=centralizare!B5)),0))
Must be entered using ctrl + alt + enter. Is should appear like so in your formula bar if done right:
{=SUMPRODUCT(--IFERROR((('3'!A2:A5=centralizare!B5)),0))}
Sample workbook: https://filetea.me/t1sjZdwkvxrRxGePZmKZyB7BQ
EDIT: It also seems that you should never had "finalizat" & "wip" in the same row, if I understand your rules right. WIth the array formula, you can check for both rules & only count those that meet both rules, not just one, and somewhat check data quality this way.:
{=SUMPRODUCT(--IFERROR((('3'!A2:A5=centralizare!B5))*('3'!C2:C5=***choose a cell/range where you put a reference to finalizat/in luru instead of wip/donw***),0))}
In other words, the general format for multiple criterial is:
{=SUMPRODUCT(--IFERROR(((CRITERIA ONE)*(CRITERIA TWO)),0))}

referencing sheets by number instead of name in cells

Lets say
sheet3.name = "d"
Is there a way I could put in a cell on sheet2 the formula =sum(sheet3!b:b) where sheet3 is being substituted with the actual sheet3 name?
I can only get =sum('d'!b:b) to work so far.
I could use VBA for this probably but I'm curious how to do this in a cell so I don't have to run a macro each time.
If you can use a UDF User Defined Function that will return the sheet name
Function SHEETNAME(number As Long) As String
SHEETNAME = Sheets(number).Name
End Function
then a formula like
=SUM(INDIRECT(SHEETNAME(3) &"!B:B"))
will return the sum from column B on sheet 3.
SHEETNAME(number) returns the sheet name of the number which is index.
So Sheet(1) returns Sheet1, etc
Use below formula anywhere in the sheet to get the sheet name - the sheet must have a filename for this to work:
=REPLACE(CELL("filename"),1,FIND("]",CELL("filename")),"")
You can either reference that cell using Indirect:
=SUM(Indirect("'"&A1&"'!B:B"))
or, if you don't want to have a second cell, you can combine the two formulas into one:
=SUM(INDIRECT("'"&REPLACE(CELL("filename"),1,FIND("]",CELL("filename")),"")&"'!B:B"))
For anyone not concerned with the order of the sheets, the post by Biff here on mrexcel.com works well.
In Excel 2013, go to the Formulas tab in the ribbon and make a defined name:
Name: SheetNames
Refers to: =GET.WORKBOOK(1)&T(NOW())
Then use a formula like this example:
=INDIRECT("'"&INDEX(MID(SheetNames,FIND("]",SheetNames)+1,255),A3)&"'!A1")
where A3 refers to the index number in a cell in the current sheet, and A1 refers to the location of the value to be retrieved from the other sheet. I.e., in the current sheet, if A3 = 2, then the formula will point to cell A1 in the second sheet of the workbook. I just use a column of index numbers in my current sheet, then drag this formula down and it fills in values from all of my other sheets.
You will need to save as a macro-enabled file (.xlsm).
I'm not sure if this is a good idea but it's the first one I could think of.
I would add additional function to your VBA project which will return actual name of your Sheet3:
Function Sheet3Name()
Sheet3Name = Sheet3.Name
End Function
Next, when you create sum formula of column B:B in Excel cell you need to do it in this way:
=SUM(INDIRECT(Sheet3Name()&"!A:A"))

Resources