Highlight cells with different values based on ID - excel

I have two columns, ID and Date. I need to highlight the rows for an ID if that ID does not have the same dates in all of the rows for that ID. e.g.:
ID Date
1 1/1/2020
1 1/1/2020
1 1/1/2020
2 2/2/2020
2 2/16/2020
2 2/2/2020
In the case of ID = 1, it shouldn't highlight anything because all of the rows for the ID = 1 have the same dates, but in the ID = 2, there's different dates (There's 2 '2/2/2020' and 1 "2/16/2020') so it should highlight all of the rows of the ID = 2.
Please note that there might be cases in which different IDs use the same set of dates. e.g.:
ID Date
1 1/1/2020
1 1/1/2020
1 1/1/2020
2 1/1/2020
2 1/16/2020
2 1/1/2020
In the case above, it should highlight only the rows that have ID = 2 since there's different dates for that ID (2 '1/1/2020' and 1 '1/16/2020').
Edit: This was achieved, without creating a macro, by using Conditional Formatting.

In the ID case of 1, it shouldn't highlight anything but in the ID 2, there's different dates so it should highlight all of the rows for that ID.
No VBA required. Use Home Tab - Conditional Formatting
Select your range and use Use a formula to determine which cells to format and use the below formula. I am taking $A$2:$B$7 for demonstration purpose. Change as applicable.
=COUNTIF($A$2:$A$7,$A2)<>COUNTIF($B$2:$B$7,$B2)
If you still want VBA then simply record a macro and perform the above steps. You will get the code which you can edit to suit your needs.
#SiddharthRout Thank you for your help! This sounds like it would work but what if 2 IDs use the same date? Lets say that by coincidence 2 IDs must have the same date, then the conditional format would highlight all of the cells regardless of the ID. ID Date 1 2/2/2020 1 2/2/2020 1 2/2/2020 2 2/2/2020 2 2/3/2020 2 2/2/2020 Do you think this can be avoided using conditional format as well? – Michael Murillo 14 hours ago
In such a case, the above formula will not work. Try the conditional formatting with this formula
=COUNTIF($A$2:$A$7,$A2)<>SUMPRODUCT(IF(CONCATENATE($A$2:$A$7,"--",$B$2:$B$7)=$A2&"--"&$B2,1,0))
What this formula does is checks for the count of ID in Column A and matches it with count of text created by concatenation of Column A and Column B.

Related

Excel counting cells based on complex criteria

Hate asking question about something as simple as an Excel formula, but seem to really need and would appreciate the help.
I have a table where the rows headings contains names and the column headings contains week numbers. Within this table I have differents numbers. Both numbers that are plus and negatives.
I want to count each cell where the row heading matches a specific name and then each cell that has a plus value with a week number less than or equal to a certain week.
I have tried to got it to work with at least some function (without it caring about plus and negative values) but haven't even gotten that to work.
I've tried with:
=SUMPRODUCT((Data!F3:F28=I1)*(Data!I2:BI2="<="&A1)*(Data!I3:BI28))
=SUMIFS(Data!I3:BI28;Data!F3:F28;I1;Data!I2:BI2;"<="&A1)
.............1 2 3 4 5
name1 -1 4 3 1 1
name2 0 0 0 0 0
I want a formula that counts for example every column header with a value less than or equal to (for example) 4, but excludes negatives and vice versa. So for the example above, the result of name1 should be 8; counts week 2, 3 and 4.
For your current example:
Formula in H3:
=SUMPRODUCT((B2:F3>=0)*(B1:F1<=4)*(A2:A3="name1"),B2:F3)

Match criteria between two tables to find maximum date within a list

I have 2 tables of data, one is only 5 columns and the second is 100s of columns, but in simplistic terms they have the formatting below. Both are hundreds of rows long.
Table 1 (is sorted ascending, all columns)
A B C D E
1 Date TeamF Trans Name TeamT
2 date1 teamF1 trans1 name1 teamT1
3 date2 teamF2 trans2 name2 teamT2
4 date3 teamF3 trans3 name3 teamT3
5 date4 teamF4 trans4 name4 teamT4
6 date5 teamF5 trans5 name5 teamT5
Table 2 (not sorted in any manner)
A B C D E F G ,etc.
1 Team Game Date Opp NameA NameB NameC ,etc...
2 team1 game1 date1 opp1 statsA1 statsB1 statsC1 ,etc...
3 team2 game2 date2 opp2 statsA2 statsB2 statsC2 ,etc...
4 team3 game3 date3 opp3 statsA3 statsB3 statsC3 ,etc...
5 team4 game4 date4 opp4 statsA4 statsB4 statsC4 ,etc...
6 team5 game5 date5 opp5 statsA5 statsB5 statsC5 ,etc...
I've been trying to get the INDEX/MATCH formula I typically use (below) a little more sophisticated to avoid some errors I've been having in data processing. I'm trying to pull the TeamT name from Table 1 and populate the stats rows in Table 2, columns E and beyond. I do this based on a
match of Names between Table1 column D and Table 2 row 1
Dates in Table 1 being <= Dates in Table 2 column C
with the following formula
my current formula =INDEX(Table1!$A:$E,MATCH(1,(Table1!$D:$D=Table2!E$1)*(Table1!$A:$A<=Table2!$C2),0),5)
As you can probably see, if there are multiple dates in Table 1 that are less than C2, I only get the first one. What I'd really like is the maximum (newest one). I've been playing with MAX/IF statements and INDEX/MATCH/IF statements but can't get the proper result. Some examples of those failed tries are below
example 1
=MAX(IF(Table1!$D:$D=Table2!E$1,IF(Table1!$A:$A<=Table2!$C2,Table1!$E:$E)))
example 2
=INDEX(Table1!$E:$E,MATCH(MAX(IF(Table1!$D:$D=Table2!E$1,Table1!$A:$A<=Table2!$C2)),IF(Table1!$D:$D=Table2!E$1,Table1!$A:$A<=Table2!$C2),0))
Any help would be appreciated. I've tried many solutions I've found, but I'm still pulling my hair out on this one.
I also have a second variation of formula where I match dates based on Dates in Table 1 being >= Dates in Table 2 column C. In that case I want the minimum match (the oldest date). I'm assuming I'd simply use MIN instead of MAX for this?
If I understand you correctly, here I have the answer for your first question.
To make the sample easier, I put everything in one sheet. You can copy to the new sheet once you are happy with the result. That way you will have the working formula.
The array formula (click Ctrl + Shift + Enter together) I used from cell K2 is:
=IFERROR(INDEX($E$2:$E$11,MATCH(MAX(IF(--($D$2:$D$11=K$1)*--($A$2:$A$11<$I2)*$A$2:$A$11,$A$2:$A$11)),IF(--($D$2:$D$11=K$1)*--($A$2:$A$11<$I2)*$A$2:$A$11,$A$2:$A$11),0)),"")
You can drag this to the fields you need. Please note this to find the most current date. Because I am not 100% sure this is what you are looking for. Therefore, in my example from cell O2, I managed to find the latest row and the formula (regular formula) is:
=IFERROR(INDEX($E$2:$E$11,LOOKUP(2,1/(--($D$2:$D$11=O$1)*--($A$2:$A$11<$I2)),(ROW($E$2:$E$11)-ROW(O$1)))),"")
For the 2nd question, I will leave it to you to find out from these two and that should do the trick.
I worked this out myself with MAXIFS to find the max date and a multi-criteria VLOOKUP function
this finds the max date less than a current row based on a name match
=VLOOKUP(MAXIFS(Table1!$A:$A,Table1!$D:$D,E$1,Table1!$A:$A,"<="&$C2)&E$1,CHOOSE({1,2},Table1!$A:$A&Table1!$D:$D,Table1!$E:$E),2,0)
the solution to a min date greater than the current row based on a name match is
=VLOOKUP(MINIFS(Table1!$A:$A,Table1!$D:$D,E$1,Table1!$A:$A,">="&$C2)&E$1,CHOOSE({1,2},Table1!$A:$A&Table1!$D:$D,Table1!$B:$B),2,0)

Excel CountIF nested in IF function

I have a dashboard I'm trying to put together and I don't understand how Excel is interpreting my formulas. I'm trying to get excel to read a cell that contains a month value, and if that value is true, then to read my dummy variables and count them. There is multiple criteria here so I used CountIFS.
Here's how the function works
=IF('Other tab'!$AI:$AI=B3,COUNTIFS('Other tab'!$BI:$BI,1,'Other Tab'!$BB:$BB,1,'Other tab'!$BC:$BC,1),"ERROR")
where any place there is a "1" there was a dummy variable created. I also tried to do this with the actual text that the dummy variables replaced and my formula still wouldn't work. I don't get an error, but the return value is "0"
Here's a sample of the data:
Current Tab:
1 A B C D E F G H
2
3 Metric January February March April May June July
Other tab:
AI BB BC BI
1 January 0 1 1
2 January 0 1 1
3 January 0 0 0
4 January 1 1 1
5 January 1 1 1
6 December 1 1 1
According to my formula, "3" should be the result here.
Update: I switched the formula to read the "0"'s on my dummy variables instead of the "1"'s and it worked to retrieve that, so why isn't it working when specifying "1" as my countif criteria?
There is no reason to put the first part in an IF statement just add it as criteria to the COUNTIFS:
=COUNTIFS('Other tab'!$AI:$AI,B3,'Other tab'!$BI:$BI,1,'Other Tab'!$BB:$BB,1,'Other tab'!$BC:$BC,1)
It appears that your data not consistent. You are looking for a text string in a series of dates that is formatted mmmm. To deal with this, in another column on the Other tab put this formula:
=TEXT(AI1,"mmmm")
And copy down.
Then change the 'Other tab'!$AI:$AI part in the above formula to new column in which you just put the 2nd formula.
This will now allow the comparison of text to text.

Transfer data from one worksheet to the next based on cell values

I had trouble titling this, and I think it is better explained with examples. I am not an extremely experienced excel user, but was asked to figure this out.
Worksheet 1 (delivered by software) is formatted like this:
12/17/2013
Hour Delivered
00.00-00.59
Employee 1 18
Employee 2 17
Total For Hour 35
01.00-01.59
Employee 1 18
Employee 2 17
Employee 3 12
Total For Hour 47
... etc until hours 24.00-24.59
The number of employees in the group per hour is different each day, so i don't think that I can just simply reference the cells.
The worksheets that I want to transfer the data from worksheet 1 to are based on date, so there is one for each day. (12/17 worksheet, 12/18 worksheet, etc...)
And this is the format of the date worksheets:
Employee 00.00-00.59 | 01.00-01.59 | etc. until hours 24.00-24.59
Employee 1 18 18
Employee 2 17 17
Employee 3 12
Employee 4
Employee 5
So basically I need the data from worksheet 1 transferred over to the individual date worksheets. I believe, the amount of employees being different for each hour/day makes this difficult. Does anyone here have any ideas of how this can be accomplished?
Also, if there are any questions, please let me know.
This should be possible without any VB in two steps. First step is to add further columns to Worksheet 1 that normalise the data. Second step is to create a pivot table using that normalised data.
By "normalise" I mean add columns in Worksheet 1 for Date, Hour, Employee and Delivered using formulae that copy values from your existing columns A and B. Let me know if you need more help with that.
Edit: adding details ...
Suppose Worksheet 1 has the values you indicated in column A and B, and that you want Hour in column D. Suppose row 1 just contains column headings. Leave row 2 totally empty. The formula in col D needs to say "If the value in col A looks like an hour, then copy it, otherwise repeat the hour from the line above." A simple way to determine if a row in Worksheet 1 is an Hour is to look for a decimal point in position 3. So put =IF(MID(A3,3,1)=".",A3,D2) in cell D3 and copy that formula down.
I'm sure you can construct a similar formula for the Date, Employee and Delivered columns.
Maybe add a condition to the formulae to say "If the value in col A starts with 'Total' then leave the cell empty".
If there aren't a lot of data and the setup is exactly how you've displayed them above, a simple formula can solve this.
Assuming that my raw export is in sheet Base, cell A1 and my intended output starts in sheet Output, cell A1, you can use this formula on cell B2:
=IF(INDEX(Base!$A:$A,MATCH(B$1,Base!$A:$A,0)+ROW(1:1),0)=$A2,OFFSET(INDEX(Base!$A:$A,MATCH(B$1,Base!$A:$A,0)+ROW(1:1),0),0,1),0)
The premise is simple. It locates the correct hour using INDEX + MATCH, then OFFSETs it by the correct number of ROWs. This is assuming, of course, that your employees are in the same location under every hour (ie Employee 1 is always one (1) row below the hour, Employee 2 is always two (2) rows below, etc). We also add a check if the employee name matches so that it will return 0 if the employee is not there.
Here are some screencaps:
Sample data:
Output:
Of course, this is just the basic premise. If you have multiple dates in a sheet, it's just a matter of manipulating this formula further. Off the top of my head, locating the correct date and adding the correct offset can also work.
Let us know if this helps or if a VBA or the Pivot option seems best.

Format Cells from 2 sheets, based on 4 column comparison

I need to find changed values in dataSet.
So I have 2 sheets with, in general, same data.
I have two columns: docID(which is unique key) and rev(which is not unique).
I need to find(highlight/display only/...) those rows, where for same docID from first sheet rev is different in the second sheet.
UPDATE 1
Sheet 1:
docID rev
1 5
2 6
3 1
Sheet 2:
docID rev
1 6
2 6
3 1
Only the first row makes an interest to me, as others did not changed.
UPDATE 2
simple if statement which should give some understanding what I need. In general this is done on similar test data set, so cells are incorrect.
=IF(NOT(AND($B6=Sheet1!$B6;$C6=Sheet1!$C6));1;0)
So values are NOT equal.
You can do this with a custom formula in Conditional Highlighting:
Select the top cell in the column docID column, then select the whole column (in the example, I assume that this is column A and you select A1 and the rev is in column B, same structure in both sheets. Adjust as to your needs)
Goto home->Conditional Formatting->New rules->Use formula to determine which cells to format and enter the following formula:
=VLOKUP(A1,Sheet1!$A:$B,2,0)<>B1
Click on format and select the format you need.
Done!

Resources