Conditional formatting formula to highlight appropriate date in range - sql

I need a formula for conditional formatting that will highlight a date between A2:Z2 which matches a number that I enter into a “Committed Sessions Cell” (A1). In row 2 there are a series of numbers that appear above each date column (1,2.3, etc). For example, if I enter a “3” in cell A1, the date in J3 should match the number 3 above it and be highlighted. The idea here is to provide a quick visual prompt for how many sessions are in a client’s contract.
Note: the sequenced numbers 1,2,3 etc in row 2 appear every 5th column (with nothing in between) but there IS other data in between the dates in row 3. Only the appropriate date should be highlighted.
A B C D E F G H I J K L M
1 3
2 1 2 3
3. 1/2/14 2/3/14 2/15/14
With grateful thanks,
~ Jay

Your example is not consistent. If you have the date every fifth column, the dates should be in columns A,F,K,P, etc. with 4 columns between 2 points.
I came up with the following formula: =AND(A2=$A$1,MOD(COLUMN(A3)-1,5)=0) which is applicable to the entire 3rd row. Create it as follow:
IMPORTANT: Select cell A3 (the reference point for the formula)
Without selecting another cell, highlight the entire row 3
Go to Conditional Formatting -> New rule
Choose "Use a formula to determine which cells to format"
In "Format values where this formula is true", put =AND(A2=$A$1,MOD(COLUMN(A3)-1,5)=0)
Choose the formatting that you want (example: Fill with yellow)
Click OK all the way
NOTES:
To change the location of your Committed Sessions, change $A$1 to another cell. Important to keep the dollar signs
The MOD function is the one that controls every fifth column. If you want the highlight every 4th column (i.e. 3 cells between each point such as A, E, I, etc.), replace the number 5 with the number 4

Related

Sum of Named Ranges to Array in Excel

I have values 1,2,3 and 2,3,4 in columes A and B respectively. I want column C to be 1+2, 2+3, 3+4. I have named the first 3 cells of column A as RANGE_A and the first 3 cells of column B as RANGE_B
I have tried sum(RANGE_A, RANGE_B), but that gives me the actual total of 15 in every cell of the output range.
I don't want to do this in VBA, and it would be cleaner if I can use the ranges like I have tried, but if all else fails i'll be just using A1+B1,A2+B2 etc..
***** EDIT ********************************
Where you want to sum two named ranges ={sum(RANGE_A, RANGE_B)} produces a scalar value, reflected in every cell of the output array, equal to the sum of both columns.
My solution is in fact, incredibly simple (thanks to QHarr, who got this right even when my original question was wrongly written!)
={RANGE_A + RANGE_B} produces an output array where each value is the sum of each pair of cells in each range. That's all i was looking for!
Cheers
J
You want to select C1:C3 and enter the following in the formula bar:
=RANGE_A*RANGE_B
then press Ctrl + Shift + Enter to enter as an array formula.
For addition you can use:
=RANGE_A+RANGE_B

Excel 2013 conditional formatting using a formula

I have a spreadsheet in Excel 2013 with Location in Column A, Material Number in Column B and types or groups of materials sorted by material number in Column I J & K. Other columns contain data that is irrelevant here.
Column B can contain the same material number in multiple cells.
I'm trying to find a simpler way to format font and color of the items in Column B by comparing if the item is located in Column I J or K, or not at all (no formatting in that case).
I was entering an individual conditional rule to compare Column B with the value in cell I3, another rule for I4, another rule for I5 and so on.
This is getting unwieldy due to the number of items now in I J & K.
There has to be a simpler, more elegant way to do this. Conditional formatting using exact match is not letting me select a range of cells for the match value.
I just need to format the text in Column B to Bold and Blue if the number exists in Column I also, or Bold and Red if it exists in Column J or Bold and Green if it exists in Column K.
Set up a conditional formatting rule that uses a formula. The formula can contain a Countif function that counts how many times the value in cell B in the current row is counted in column I. For example, starting in row 2, select B2 and add a formatting rule with the formula
=COUNTIF($I:$I,$B2)
Take care to use the current row number in the formula and don't use a dollar sign $ in front of the row number. Set three rules, one for column I, one for J and another one for K.
You don't need a new set of rules for each row. Just apply the three rules to all the rows required.

How to compare a list of rows to another list of rows in Excel?

I am trying to figure out if there are any differences between a list of data with another. In order for a row of data to "match" with another row, the row must have the same values in their corresponding column. The rows themselves do not have to be in any particular order. In particular, I am dealing with a parts list, where there are part numbers, descriptions, etc. I am trying to figure out if any rows of data are different from rows of data from another list.
I found Compare two sheets using arrays, which may have the answer to my problem, but I am having trouble figuring out how to adapt to my code due to inexperience in Visual Basic.
I was able to get it to work for a single column of data, comparing one column of data from one sheet to another, but cannot get it to compare entire rows of data.
Here is an example of I want this to work:
Sheet 1 Sheet 2
Column 1 Column 2 Column 1 Column 2
Row 1 22a 33 11 11
Row 2 22a 33a 22a 33
Row 3 55 22b 55 23b
The code in the link will tell you what is not in sheet 1 but in sheet 2 and vice versa. In this example, I would like the code to tell me Sheet 1 Row 2 and Sheet 1 Row 3 are not in Sheet 2, and Sheet 2 Row 1 and Sheet 2 Row 3 are not in Sheet 1 (Sheet 1 Row 1 and Sheet 2 Row 2 match).
If that is ok by you, you can do it without VBA using the following formula:
={IF(IFERROR(MATCH(A1&"|"&B1;Sheet7!$A$1:$A$3&"|"&Sheet7!$B$1:$B$3;0);-1)=-1;"Unique";"")}
Assuming that each of your tables start in A1 (so that the tables with three entries span A1:B3), and entering this formula into C1 (and copying it down), press CTRL+SHIFT+ENTER when entering the formula to create an array formula, this will show the word "Unique" in column C if the pair in that row on that sheet is not in any of the row-pairs on sheet 2.
You can then use conditional formatting to highlight unique rows, filter on the tables to include only unique rows, or some other way of doing what you need.
NOTE 1: I have entered my numbers in Sheet6 and Sheet7 instead of 1 and 2. The formula written above goes into Sheet6.
NOTE 2: My language use ; instead of , as function separator, so if yours use , you need to change that.
NOTE 3: You will need to expand the ranges Sheet7!$A$1:$A$3 and Sheet7!$B$1:$B$3 if your set grows (this will happen automatically if new rows are inserted in between the old ones). The best is still probably to create named ranges for each of the 4 columns, exchange the references with those, and manage the named ranges instead of the formulas.
NOTE 4: If your data set contains the character "|", you need to change that as well, to match some character that you for sure do not have there.
Alternatively you could in column C on each cheet enter (assuming first entry in C1)
=A1&"|"&B1"
and copy this down, then run the solution from your copied example using that C column instead of on A1 and B1.

Trailing Average Using AverageIf in Excel

I am trying to find the average for the last 3 instances only. I am using the AVERAGEIF statement and it will calculate the average for the entire range but I need it to only calculate for that last 3 instances it finds (or less if there is less than 3 available). I need the entire column for G and H to have the average for the last 3 games that the Team played.
This is what I have:
=AVERAGEIF(B3:C17,B17,D3:E17)
You can do this with array formulas (They have to be entered using the keys Ctrl+Shift+Enter)...
Basic steps are:
Find the row (including and above current) that is the third highest row number containing the team name (or use row 1 otherwise)
Use the INDIRECT ranges in your AVERAGEIF from B-that_row to C-current_row and D_that_row to E-current_row
So in cell F17 you would have the formula
{=AVERAGEIF(INDIRECT("B"&LARGE(IF(--($B$3:B17=B17)+($C$3:C17=B17),ROW($B$3:B17),1),3)&":"&CELL("address",C17)),B17,INDIRECT("D"&LARGE(IF(--($B$3:B17=B17)+($C$3:C17=B17),ROW($B$3:B17),1),3)&":"&CELL("address",E17)))}
We repeat some of the logic, because we have two ranges (criteria range and average range).
IF(--($B$3:B17=B17)+($C$3:C17=B17),ROW($B$3:B17),1) means that if column B or (using +) column C has the value of in B17, give me the row number, otherwise 1 (our <3 case... we could make this 3, the first row of team names)
LARGE(...,3) will give us the third highest of this array --> the third highest row number having our team name
INDIRECT("B"&...&":"&CELL("address",C17)) is going to give us the range using our third highest row number to the current row, columns B and C
then we do exactly the same thing as you were doing in AVERAGEIF but using this INDIRECT range and the equivalent for columns D and E
Fun question! Good luck. And remember to use Ctrl+Shift+Enter to enter it!
EDIT The above was giving an #NUM! error for the first two rows - that was because the LARGE function was trying to get the third largest in an array of 2! Also noticed that there were some cases where the column letter needed to be absolute (i.e. $) for copying to the Away column. So the updated formula:
{=AVERAGEIF(INDIRECT("B"&LARGE(IF(--($B$3:$B17=B17)+($C$3:$C17=B17),ROW($B$3:$B17),1),MIN(3,ROW()-2))&":"&CELL("address",$C17)),B17,INDIRECT("D"&LARGE(IF(--($B$3:$B17=B17)+($C$3:$C17=B17),ROW($B$3:$B17),1),MIN(3,ROW()-2))&":"&CELL("address",$E17)))}
Replaced the 3 with MIN(3,ROW()-2) so that we get 3 if there are, but 1 or 2 if we are in one of the first two data rows
OK I posted this prematurely and attempted to delete it when I realised it wouldn't work. It should work now.... providing you add another condition which is the game dates in column A. Remember that this is an array formula so hit ctrl+shift+enter. Dates in column A; teams in column B; stats in column D. This formula can reside somewhere permanent on the sheet so you can enter the team name (shown as F13 here) to get the three most recent stats.
=AVERAGE(VLOOKUP(LARGE(IF(B3:B24=F13,A3:A24),1),A3:D24,4),VLOOKUP(LARGE(IF(B3:B24=F13,A3:A24),2),A3:D24,4),VLOOKUP(LARGE(IF(B3:B24=F13,A3:A24),3),A3:D24,4))

In excel, want to only sum certain values(not as easy as SUMIF)?

So I have two columns on named program and one with cost values. The three programs are ABC, A, B, and C. I want to sum the costs of all programs that contain A. All that contain B. And all that contain C. ABC clearly is included in all the sums. The problem is that to get just these programs the spreadsheet has a filter on it which messes sumif up. Can someone help? Here is an example of what I mean:
program cost
A 5.00
B 4.00
ABC 9.00
A 2.00
so I would want in three separate cells "sum with A"=16.00, "sum with B"=13.00, "sum with C"=9.00.
Item | Total
A | 16
B | 13
C | 9
Assuming your above range is in A1:B5, my first formula is the following Array formula:
{=SUM(IF(ISERROR(FIND(B6,$A$1:$A$5)),0,$B$1:$B$5))}
You create an Array formula by entering the formula and holding down the Ctrl+Shift keys while you hit Enter. In my solution, I've created an area where I calculate by totals and have a column (called Item in this case) which indicates the letter I see in the original A column.
If you were trying to enter this using VBA, you would use the FormulaArray property:
Selection.FormulaArray ="SUM(IF(ISERROR(FIND(B6,$A$1:$A$5)),0,$B$1:$B$5))"
Update
Restricting the calculation to only visible cells is a bit more complicated. Suppose we have your original data in cells A1:B5. Let's also suppose our test values start in cell C7 (diagonal to the source data). Our totals formula would look like:
=SUMPRODUCT(SUBTOTAL(3,OFFSET($B$1:$B$5,ROW($B$1:$B$5)-ROW($B$1),0,1)), --NOT(ISERROR(FIND(C7,$A$1:$A$5))), $B$1:$B$5)
The following portion returns a range over the cells
OFFSET($B$1:$B$5,ROW($B$1:$B$5)-ROW($B$1),0,1)
This portion returns 1 for each visible cell and 0 for invisible cell
SUBTOTAL(3,OFFSET($B$1:$B$5,ROW($B$1:$B$5)-ROW($B$1),0,1))
This portion is our criteria. NOT(ISERROR(... will return TRUE or FALSE. The double negative sign -- converts that value into a negative integer and then removes that negation.
--NOT(ISERROR(FIND(C7,$A$1:$A$5)))
Lastly, the SUMPRODUCT function multiplies the matching arrays to each other and executes the sum. The first two arrays return a series of 0's or 1's. If the row is both visible and matches our criteria, then we get 1*1 multipled by the given value in the cell. If the given cell is not visible or does not match the criteria, one of the two return a zero and it zeroes out the entire item.