Conditional sum with merged cells using Sumiif() - excel

Scenario is 2 worksheets, Sheet1 and Sheet2.
Sheet1 config:
Sheet2 Config:
The problem:
The customer wants to input the daily amounts of bananas in Sheet2 (C:C) and have the totals automatically add in Sheet1 for the week number. The problem I'm facing with this, I believe is the merged cells. I was successful when I removed the merged cells and added the week number to all the cells with this formula ( =SUMIF(A:A,E3,'Sheet2!C:C) ) But the customer would prefer to keep the merged cells, and with that it only returns the first value of that week. Am I missing something simple here? Can't seem to wrap my head around this.

Merged cells are a bad idea for several reasons and should be avoided.
That does not mean that you can't achieve the look your client wants. You can fill the numbers into all the unmerged cells and then use conditional formatting to hide six of the seven numbers. In the screenshot below, column A has a conditional format with this formula
=MOD((ROW()+2)/7,1)
The format applied is custom number format ;;; (or use white font on white background). Adjust the formula if your data starts on a different row.
Note that the formula bar clearly shows that the selected cell has the value 26.

This is what I found:
=SUM(IF(LOOKUP(ROW(Sheet2!$A$2:$A$15),ROW(Sheet2!$A$2:$A$15)/(Sheet2!$A$2:$A$15<>""),Sheet2!$A$2:$A$15)=A2,Sheet2!$C$2:$C$15))
This is an array formula. Enter into sheet 1 C2. Hit Ctrl Shift Enter. Then copy down.

From my point of view, the important aspect to this specific layout is that a week has 7 days and you are listing every day in the week. A merged cell is identified by the top-left cell in the merged area. Looking for 26 returns A2 and looking for 27 returns A9. If you reference column C with those row numbers and extend the range to 7 rows then you can sum for the matching week.
In G2 (per the image supplied),
'volatile OFFSET function
=SUM(OFFSET(INDEX(C:C, MATCH(E2, A:A, 0)), 0, 0, 7, 1))
'non-volatile INDEX function
=SUM(INDEX(C:C, MATCH(E2, A:A, 0)):INDEX(C:C, MATCH(E2, A:A, 0)+6))
The dates in either table are inconsequential beyond visual reference.

Related

INDEX MATCH not working on few cells (Same Formula)

After a lot of brainstorming I leared to write this forumula and it actually worked, however, when I tried to drag it down it did not work on some of the random cells in sheet and gave #REF error. I am not able to understand that when the value is there and the formula is working oo other cells then why on dragging it did not work on few.
Please helpm thanks in advance
Here is the formula
=INDEX(Volume!$D$3:$F$68,MATCH(B23,Volume!$A$3:$A$68,0),MATCH(D23,Volume!$D$2:$F$2,0),MATCH(E23,Volume!$B$3:$B$68,0))
Attached is the link to access Excel sheet because samme formula on dragging miss some of the random cells and shows #REF.
https://docs.google.com/spreadsheets/d/1fEyTc3SUAgumFr54HC2LVLoXGAbum9uG/edit?usp=sharing&ouid=102884722585384256735&rtpof=true&sd=true
It looks like you're trying to check three columns with an INDEX formula but your fourth argument is wrong (the 'MATCH(E23,Volume!$B$3:$B$68,0)' part). This argument selects which range of data should be used but you're giving it a value outside the range of data e.g. that part of the formula in cell H23 on the 'Sea Freight Rates' sheet returns 24 but there's no 24th column of data you've specified. The formula only works in some cases by pure accident and because of how the data on the 'Volume' sheet is laid out.
This is the formula that you want to use in cell H2 and then drag down. The 'MATCH($B2&$E2' part joins the value in column B and E together to give a unique combination (e.g. 'CNNBO PT20DC' for cell H2) while the 'Volume!$A$2:$A$68&Volume!$B$2:$B$68' part produces an array of all possible combinations from the relevant columns in the 'Volume' sheet. It will look for 'CNNBO PT20DC' in this array and return the relevant row number. The formula then looks for the correct 'Destination Port' like you have before which gives the relevant column number. You'll then get the correct value and that row and column:
=INDEX(Volume!$D$2:$F$68,MATCH($B2&$E2,Volume!$A$2:$A$68&Volume!$B$2:$B$68,0),MATCH($D2,Volume!$D$2:$F$2,0))
Side-note, you have two rows for INNSA PT and 20DC on the 'Volume' sheet (rows 6 and 22) - is that correct?

Conditional formatting based off the previous X number of cells

I am trying to setup conditional formatting so that the formatting takes effect if the previous 4 cells in a column are blank. I need the range inside the conditional formatting formula to move as it is applied to cells below it, for example:
If I am tracking sales by store, if there is a 4 week period where a certain store doesn't record any sales I want those 4 weeks to automatically highlight.
My current formula is to select cells B5:B11, enter the formula =SUM(B2:B5)=0 to trigger the cell highlighting.
My problem is that when I look at cell B6 the range it looks for to be blank is still B2:B5 and I need it to be B3:B6.
Is there a way to set this up so that the range will change as it moves down a column?
This one has gotten me thinking a bit, and here is my solution for it.
My solution needs to use four conditional formattings, i.e. set up four conditional formattings in each cell, and then use format painter to apply the conditional format to all the cells.
Suppose your week table is in range A1:D20, and suppose you want to highlight cells if there are at least (not only) four consecutive blank cells.
Highlight cell B2, and then set up conditional formatting using the following four formulas:
=SUM(OFFSET($B2,0,0,4,1))=0
=SUM(OFFSET($B2,-1,0,4,1))=0
=SUM(OFFSET($B2,-2,0,4,1))=0
=SUM(OFFSET($B2,-3,0,4,1))=0
Then should have something similar to the following when examing the conditional formatting window:
Lastly, highlight cell B2, use the Format Painter function under Home tab and then apply the format to the rest of the cells in the week table. Then you should have something similar to the following:
It is easy to find the first blank cell of four consecutive blank cells, but it is difficult to identify the second, third and fourth blank cells using one formula. The workaround uses four different formulas to identify each of the four blank cells (I hope this makes sense). Please note the following is only looking at Column B of my example, not all columns:
Not pretty, but it works. This will highlight all occasions where the store has at least 4 weeks of consecutive donuts.
Columns B:D = Original Data
Columns E:G = Helper Set 1
Columns H:J = Helper Set 2
There's probably a way to get just one helper set, but this works and was easy to validate. First I added 3 empty rows above week 1.
In cells E4, E5 and E6 place a 0. You don't have to, you could also leave these blank.
Cell E5 formula, which is counting the number of consecutive blanks:
=IF(ISBLANK(B5),E4+1,0)
Drag it over to column G and drag it down.
Cell H5 formula, which is looking at 4 weeks later to see if there were consecutive blanks found in helper set 1:
=IF(E8>=4,"Yes","No")
Drag it over to column J and drag it down. Also, in the row above it, repeat week 1 values.
Lastly, select your original data range (B5:D14) and create this conditional formatting formula:
=(OR(H5="Yes",H4="Yes",H3="Yes",H2="Yes"))
Once you're satisfied, you can hide rows 2:4 and can also hide your helper columns.
Apply the following condition to each respective ranges:
Range: B2:D2:
=SUM(B2:B5)=0
Range: B3:D3:
=OR(SUM(B2:B5)=0, SUM(B3:B6)=0)
Range: B4:D4:
=OR(SUM(B2:B5)=0, SUM(B3:B6)=0, SUM(B4:B7)=0)
Range: B4:D8:
=OR(SUM(B2:B5)=0, SUM(B3:B6)=0, SUM(B4:B7)=0, SUM(B5:B8)=0)
Result with sample data:

Conditional Formatting Based On Multiple Columns

Sheet1
[
Sheet2
[
On Sheet 1 I have four columns Col A= 1st adjustment, Col B= 1st Check, Col C= 2nd Adjustment, Col D= 2nd Check.
The values in these columns are either 0 or non 0. Always a number. For the two adjustment columns I format them to be Red (if they are non-zero) and for the two check columns I format them to be Yellow (if they are non-zero).
On sheet 2 there is a column that pulls and combines the the sets of adjustments and checks and assigns them to the correct employee ID #.
Somehow I need the formatting on the column in sheet 2 to be red if the number came from an adjustment column on the other page and yellow if the number came from a check column on the other page. And no color if it is equal to 0.
What is the best way to do this? I have not been able to find a solution.
The conditional formatting rules I have are all applied to column C Sheet 2. They are:
#1- Cell value equal to = 0 (no fill)
#2 Cell value equal to =Sheet1!$E1 (yellow fill)
#3 Cell value equal to =Sheet1!$C1 (yellow fill)
#4 Cell value equal to =Sheet1!$D1 (red fill)
#5 Cell value equal to =Sheet1!$B1 (red fill)
Assuming that both lists start in A1, put this formula in cell D2 of Sheet2:
=IF(C2=0,0,IF(C2=INDEX(Sheet1!$B$2:$E$7,B2,(A2-1)*2+1),1,2))
Then select the range C2:C13 and open the conditional formatting menu. Add 3 new rules based on formula. The first formula is:
=D2=1
and set the format as filled in red. The second formula is:
=D2=2
and set the format as filled in yellow. The third formula is:
=D2=0
and set the format as unfilled (which is not the same as no format selected). This last rule is not strictly necessary if none is going to change the format of your range manually. Still...
Note that each formula for the conditional formatting is written without any $ that would lock the reference. Therefore each cell in the range $C$2:$C$13 will translate that formula relatively to its own position. Cell C2 will "look into" cell D2, cell C3 will look into cell D3, C4 into D4 and so on. You can of course hide column D and the conditional formatting will still work.
You could also make it without using an extra column. Just edit the formula meant for cell D2 accordingly and use it in your rules. Something like this should work:
=IF(C2=0,0,IF(C2=INDEX(Sheet1!$B$2:$E$7,B2,(A2-1)*2+1),1,2))=1
=IF(C2=0,0,IF(C2=INDEX(Sheet1!$B$2:$E$7,B2,(A2-1)*2+1),1,2))=2
=IF(C2=0,0,IF(C2=INDEX(Sheet1!$B$2:$E$7,B2,(A2-1)*2+1),1,2))=0
Formula details (as asked in comments)
B2 is for the row. In the context of the INDEX function it says at what row of the range ($B$2:$E$7 in the formula we see here) the INDEX function has to "look". If B2 is 1, it will consider the first row of the range (in our case row 2). If it's 2, it will consider the second row (in our case row 3).
(A2-1)*2+1 stands for the column. In the context of the INDEX function it says at what column of the range ($B$2:$E$7 in the formula we see here) the INDEX function has to "look". If the result is 1, it will consider the first column of the range (in our case the B column). If it's 2, it will consider the second column (in our case the C column).
About (A2-1)*2+1: let's change it a bit so it will be easier to visualize while i explain it:
1+(A2-1)*2
We can divide the formula in 2 parts: the 1 which stand as our starting point (the first column) and the (A2-1)*2+1 which deal with the shift in columns according to the shift in weeks. In cell A2 we find the number of the week. In the first sheet we have 2 columns for each weeks. Therefore when the week shifts by 1, our target column will have to shift by 2. We can't just multiply by 2 the week sheet because it's the shift from the first week that counts for 2, not the actual value. At the first week we will have no shift. Therefore our shift will have to be 0; but we can't just use a 0 because there is no "zero column" in a range. Therefore we need to have our starting value of 1 that is summed to the shift. This way for the first week we will have:
1+(1-1)*2
1+(0)*2
1+0
1
First column of the range $B$2:$E$7 (which is column B). For the second week we will have:
1+(2-1)*2
1+(1)*2
1+2
3
Third column of the range $B$2:$E$7 (which is column D).
Over all the formula IF(C2=INDEX(Sheet1!$B$2:$E$7,B2,(A2-1)*2+1),1,2) basically checks if the value in C2 is the same as the first column of the given week. If it's the same value it returns 1, otherwise it returns 2 (basically assuming that the value will be equal to the one in second colum of the given week).
Report any question you have or bug you have encountered. If, according to your judgment, this answer (or any other) is the best solution to your problem you have the privilege to accept it (link).
Let me give you a general approach for conditional formatting, based on a formula:
First you try to set up your formula, which you enter in some cell. The result of the formula should be TRUE in case you want the formatting to be applied, and FALSE in all other cases.
Please edit your question again, showing the formula you have tried for configuring this.
Oh, you just want to copy the formatting of that first sheet. But tell me, how is the formatting of that first sheet determined? Is it also the result of a conditional formatting? And about the numbers of the ADJ/Check column, is that just the sum of the values in the first sheet?

Adding all the values below the current cell in Excel

I am trying to display the total sum of all the numbers for a particular column. I want the sum to be displayed above the column as follows:
21 30
A B
6 5
6 10
6 10
3 5
I know I can sum the values and display it at the bottom of the column using =SUM(A3:INDIRECT("D"&ROW()-2)), however I am not getting a way to display it at the top of the column.
Please guide.
Based on the comments and the previous answers I suggest following formula, entered in cell A1:
=SUM(OFFSET(A$2,0,0,ROWS(b:b)-1))
You can then copy/paste to the right till second last column.
You could also modify your formula in A1 like this to achieve the same:
=SUM(INDIRECT("A2:A"&ROWS(A:A)-2))
But then you cannot copy/paste to the right...
A more general approach with your idea would be:
=SUM(INDIRECT(ADDRESS(ROW()+1,COLUMN())&":"&ADDRESS(ROWS(A:A),COLUMN())))
You can then copy/paste to the right till last column.
Some explanations:
Both formula sums up every value in the range from A2 till the bottom of column A (i.e. for Excel 2010 this would be A2:A1048576)
It doesn't matter if there are blanks or cells without value; the formula sums up only the numbers
I put A$2 and B:B in the OFFSET formula to avoid circular references, since I'm writing in cell A1 and I cannot write A$1 nor A:A
With the INDIRECT formula you don't have to worry about circular references
Further commenting (sorry, I don't have the credits to comment at the right place under the question):
Phylogenesis formula =SUM(A3:A65535) could also do the work, isn't it?
Didn't understand your question at first, because you talk of "sum of all the numbers for a particular row" but then you sum columns, isn't it?
When I'm doing something like this, I prefer to not include any empty cells beneath the range I'm summing, because I've had errors in the past as the result of including them (usually because there's a cell way down in the column somewhere that I'm not expecting to have a value). I'm assuming that A & B are your column headers. Assuming that, here is how I would do it. This is your formula for cell A1:
=SUM(OFFSET(A$1,2,0,COUNTA(A$3:A$65535)))
Explanation
I'm updating this with a brief explanation, per the OP's request.
According to ExcelFunctions.net:
The Excel Offset function returns range of cells that is a specified number of rows and columns from an initial supplied range.
The function reference for OFFSET is:
=OFFSET(reference, rows, cols, [height], [width])
What this formula does is create a dynamic range based on the number of cells in the selection, relative to cell A$1. This is an offset of two rows and no columns, which starts the range at A$3. The height of the range is the total number of filled cells in the range A$3:A$65535. The assumption here is that there are no blank cells in the range, which there were not in the sample data.

Formatting a cell based on perpendicular row/column values

Trying to create a Gantt chart look in Excel. I have two columns, A and B (A = start date, B = End Date).
Across the top of the page (Row 2) I have a column with a date for every date of the project (custom formatted with "d" for readability, with the name of the month in Row 1.)
I'm now trying to apply conditional formatting rules to turn the cell in the column a specific colour (say, green) if:
the value in A[this row] is greater-than-or-equal-to [this column]2.
and
the value in B[this row] less-than-or-equal-to [this column]2.
I've dug through a few answers recommending ADDRESS() and INDIRECT(), but I'm stumped on getting this to work. Any thoughts?
You can use AND to combine the conditions. I'm assuming the 'Gantt chart' starts as from column C and the active row is 2 here.
Select C2 and the rest of the row (to 31, 30 or 28/29 depending on the number of days in the month).
Pull up conditional formatting with formula and put:
=AND(C2>=$A2,C2<=$B2)
Pick the format fill green and that should do it
In conditional formatting if you use the first cell of your selection in the formula it automatically turns that into a relative formula.
For example if you use the formula: =A1>5 and select cells A1:B5 it will check each cell to see if its >5 not just cell A1 (so it automatically increments the row and the column for you). Usually this is preferred over using indirect but sometimes indirect is necessary.
So using indirect you can utilize the row() and column() functions. So in your example:
the value in A[this row] is greater-than-or-equal-to [this column]2.
and
the value in B[this row] less-than-or-equal-to [this column]2.
Would look like:
=AND(INDIRECT("A"&ROW()) >= INDIRECT(CHAR(COLUMN()+64)&"2"), INDIRECT("B"&ROW()) <= INDIRECT(CHAR(COLUMN()+64)&"2"))
Hopefully that helps
It works for me without ADDRESS or INDIRECT. This is the formula inside the conditional formatting. If I have to guess what's going on, it's most likely that you are not placing the proper anchors ($).
=AND(C$2>=$A3,C$2<=$B3)

Resources