I have a simple excel spreadsheet that is a daily updated list of counters. The format of the sheet is as follows:
A B C D E
date name computer info counter
Example:
A B C D E
04/04/2012 John 186 Workstation 4813
04/04/2012 Mary 181 Workstation 2273
04/05/2012 John 186 Workstation 4822
04/05/2012 Mary 181 Workstation 2274
04/06/2012 John 186 Workstation 4854
04/06/2012 Mary 181 Workstation 2275
04/06/2012 Bill 183 Workstation 3698
and son on….
What I need to be able to do is combine all like cells. So for instance combine all of the rows for each month and subtract the last E column from the first one so it it would look like the following in a new sheet.
A B C D E
April 2012 John 186 Workstation 41
April 2012 Mary 181 Workstation 2
April 2012 Bill 183 Workstation 0
and so on for each one…keeping in mind this is updated daily and have many days, months and years.
I have no idea how to even think about doing this but I assume I would need a macro. If anyone has any assistance that would be great!
I have spent some time on this, and it feels like I have finally got what you need. I would have uploaded a sample file, but file sharing sites are blocked here :).
Now I know, you want your output in a different tab, but bear with me on this for now.
The following solution is lengthy (expected because of the nature of your question). Follow what is done here to the T, and don’t care about intermediate errors that might popup in some cells, it will all be sorted out in some time.
I am assuming your sheet looks like yellow part of the image. (Never mind the dates in the first column, they are all April 2012 dates, that’s what matters.)
In cell F2, paste the following formula
=IF(A2="","",MONTH(A2))
In cell G2, paste the following formula,
=IF(A2="","",YEAR(A2))
In cell H2, paste the following formula,
=IF(B2="","",B2&"|"&F2&"@"&G2)
I am using the characters “|” and “@” here, because I am assuming they do not occur in any if the names!! Please make sure if this is so!!
Now copy cells F2 to H2, and paste them all the way down till wherever you have data.
Now, I am also assuming that you have 8000 rows of data. If you have more than 8000 rows, replace all ‘8000’s in the following formulae with the number you desire.
In cell Q2, paste the following formula,
=IF(ISERROR(INDEX($H$2:$H$8000,MATCH(0,COUNTIF($Q$1:Q1,$H$2:$H$8000),0))),"",INDEX($H$2:$H$8000,MATCH(0,COUNTIF($Q$1:Q1,$H$2:$H$8000),0)))
Please note that this is an array formula, and it needs to be entered with Ctrl+Shift+Enter. So in Q2, you paste this formula in the formula bar, and instead of pressing Enter, you press Ctrl + Shift + Enter. I have borrowed this formula from here.You may check out the site to see how this formula works.
Now, in the cell K2, paste the following formula
=IF(OR(Q2=0,Q2=""),"",LEFT(Q2,FIND("|",Q2)-1))
In the cell P2, paste the following formula
=IF(OR(Q2=0,Q2=""),"",VALUE(RIGHT(Q2,LEN(Q2)-(FIND("@",Q2)))))
In the cell O2, paste the following formula
=IF(OR(Q2=0,Q2=""),"",VALUE(MID(Q2,FIND("|",Q2)+1,LEN(Q2)-LEN(K2)-LEN(P2)-2)))
In the cell J2, paste the following formula
=IF(OR(Q2=0,Q2=""),"",TEXT(DATE(P2,O2,1),"mmm yyyy"))
In the cell L2, paste the following formula
=IF(OR(Q2=0,Q2=""),"",INDEX($C$2:$C$8000,MATCH(K2,$B$2:$B$8000,0)))
In the cell M2, paste the following formula
=IF(OR(Q2=0,Q2=""),"",INDEX($D$2:$D$8000,MATCH(K2,$B$2:$B$8000,0)))
In the cell N2, paste the following formula,
=IF(OR(Q2=0,Q2=""),"",MAX(IF((($B$2:$B$8000=K2)*($F$2:$F$8000=O2)*($G$2:$G$8000=P2)),($E$2:$E$8000)))-MIN(IF((($B$2:$B$8000=K2)*($F$2:$F$8000=O2)*($G$2:$G$8000=P2)),($E$2:$E$8000))))
Again, please note that this is an array formula, and it needs to be entered with Ctrl+Shift+Enter. Make sure you have done all the steps above
Now select cells from J2 to Q2, copy them and paste them to as far as required. In the example screenshot, this would be upto row number 5 (to cover all possibilities).
You finally have the table you require. You may now link this table in other places using a simple ‘equals to’ relation. Also, you can hide all these extra columns from your data sheet if you so wish.
Whew!! I really hope that solved your problem!! I think I deserve a pat on the back for all this effort!! Hope it helps! 🙂
Answer:
Add 4 new columns (F
to I
) to your sheet and enter the following formulas:
(assuming 100 rows of data: adjust as required!)
F --> =DATE(YEAR(A1), MONTH(A1), 1)
G --> =MIN(IF(($B$1:$B$100=$B1)*($C$1:$C$100=$C1)*($D$1:$D$100=$D1)*($F$1:$F$100=$F1),$E$1:$E$100)) [press CTRL+SHIFT+ENTER (this is an array formula)]
H --> =MAX(IF(($B$1:$B$100=$B1)*($C$1:$C$100=$C1)*($D$1:$D$100=$D1)*($F$1:$F$100=$F1),$E$1:$E$100)) [press CTRL+SHIFT+ENTER (this is an array formula)]
I --> =H1-G1
(drag down to expand the formulas to all rows)
It should look like this:
A B C D E F G H I
04/04/2012 John 186 Workstation 4813 =DATE(YEAR(A1), MONTH(A1), 1) {=MIN(IF(($B$1:$B$100=$B1)... {=MAX(IF(($B$1:$B$100=$B1)... =H1-G1
04/04/2012 Mary 181 Workstation 2273 =DATE(YEAR(A2), MONTH(A2), 1) {=MIN(IF(($B$1:$B$100=$B2)... {=MAX(IF(($B$1:$B$100=$B2)... =H2-G2
04/05/2012 John 186 Workstation 4822 =DATE(YEAR(A3), MONTH(A3), 1) {=MIN(IF(($B$1:$B$100=$B3)... {=MAX(IF(($B$1:$B$100=$B3)... =H3-G3
04/05/2012 Mary 181 Workstation 2274 =DATE(YEAR(A4), MONTH(A4), 1) {=MIN(IF(($B$1:$B$100=$B4)... {=MAX(IF(($B$1:$B$100=$B4)... =H4-G4
04/06/2012 John 186 Workstation 4854 =DATE(YEAR(A5), MONTH(A5), 1) {=MIN(IF(($B$1:$B$100=$B5)... {=MAX(IF(($B$1:$B$100=$B5)... =H5-G5
04/06/2012 Mary 181 Workstation 2275 =DATE(YEAR(A6), MONTH(A6), 1) {=MIN(IF(($B$1:$B$100=$B6)... {=MAX(IF(($B$1:$B$100=$B6)... =H6-G6
04/06/2012 Bill 183 Workstation 3698 =DATE(YEAR(A7), MONTH(A7), 1) {=MIN(IF(($B$1:$B$100=$B7)... {=MAX(IF(($B$1:$B$100=$B7)... =H7-G7
The result being:
A B C D E F G H I
04/04/2012 John 186 Workstation 4813 04/01/2012 4813 4854 41
04/04/2012 Mary 181 Workstation 2273 04/01/2012 2273 2275 2
04/05/2012 John 186 Workstation 4822 04/01/2012 4813 4854 41
04/05/2012 Mary 181 Workstation 2274 04/01/2012 2273 2275 2
04/06/2012 John 186 Workstation 4854 04/01/2012 4813 4854 41
04/06/2012 Mary 181 Workstation 2275 04/01/2012 2273 2275 2
04/06/2012 Bill 183 Workstation 3698 04/01/2012 3698 3698 0
For clarity’s sake, let’s get references for the relevant data in another sheet. Assuming the data above is stored in Sheet1
, enter the following on Sheet2
:
A B C D E
=Sheet1!F1 =Sheet1!B1 =Sheet1!C1 =Sheet1!D1 =Sheet1!I1
=Sheet1!F2 =Sheet1!B2 =Sheet1!C2 =Sheet1!D2 =Sheet1!I2
...
The result being:
A B C D E
04/01/2012 John 186 Workstation 41
04/01/2012 Mary 181 Workstation 2
04/01/2012 John 186 Workstation 41
04/01/2012 Mary 181 Workstation 2
04/01/2012 John 186 Workstation 41
04/01/2012 Mary 181 Workstation 2
04/01/2012 Bill 183 Workstation 0
Finally, on Sheet2
:
-
change the format of column A to “custom” /
mmmm yyyy
, so that the date is displayed as you like (i.e.April 2012
instead of04/01/2012
) -
last but not least: use excel’s advanced filter to get rid of the duplicates.
Tags: excelexcel