Counting separate instances

Marmaduke0703

New Member
Joined
Jan 25, 2021
Messages
13
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have a sheet that I need some help with please...

Each month, we need to summarise the absence information from a table similar to the below. I have a countif to total up the complete number of days but what we would like it know is how many separate instances there are for each row. Using the example below, Emp 1 and Emp 6 will need to show as 2 (currently hardcoded) as they came back into work ("W") between their two absences.

I've tried writing an if statement to compare the cell to the left (if the current day is "S" but the previous day is "W"...) but I need to account for any "R" or "H" values etc.

Any help will be greatly appreciated!
Thanks :)


Book1 (003).xlsx
ABCDEFGHIJKLMNOPQRSTU
3NameCount "S" DaysCount instances separated by work01/1002/1003/1004/1005/1006/1007/1008/1009/1010/1011/1012/1013/1014/1015/1016/1017/1018/10
4Emp 142RRSSWWRRSSWWRRWWWW
5Emp 211RRHHHHRRWRRSWWWHHR
6Emp 300HHRRWWWWRRWWWWRRWW
7Emp 400RWWWRRWWWWWRRWWWWR
8Emp 581WWWHRRSSSSRRSSSSRR
9Emp 692SSSSRRWWWRRSSSSSRR
10Emp 7131SSSSRRSSSSSRRSSSSR
11Emp 821SRRSWWWRRWWWWRRWWW
12Emp 900RWWWWWRRWWWWRRHHHH
13Emp 10141SSSSSRRSSSSRRSSSSS
14Emp 1100HHHHRRWWWWWRRWWWWR
15Emp 1200WWWWRRWWWWWRRWWWWW
16Emp 1321RWWWWWRRWWWWRRSSWW
17Emp 1461WWRRSSSSRRSSWWRRWW
18Emp 1521SSWWRRWWWWWRRHHHRR
19Emp 1631WWRRSSSWWRRWWWRRWW
20Emp 17121RSSSSRRSSSSRRSSSSR
21Emp 18121SRRSSSSRRSSSSRRSSS
Sheet1
Cell Formulas
RangeFormula
B4:B21B4=COUNTIF(D4:U4,"S")
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hello, The CountIf should work okay. You can insert two more columns so that there is a column for H, R, W, S. Or, you could write the formula in columns AA, AB, AC, AD for HRWS. You don't need to show people your work, but you know where the work is.
 
Upvote 0
Hello, The CountIf should work okay. You can insert two more columns so that there is a column for H, R, W, S. Or, you could write the formula in columns AA, AB, AC, AD for HRWS. You don't need to show people your work, but you know where the work is.
Hi :)

Apologies, I don't think I explained it very well.

What I need to show is how many separate periods of absence someone had (not the total days). So say they were "S" on monday and tuesday (first period of absence), came back into work ("W") on wednesday and thursday, then were absent ("S") again on friday (second absence) it would show as 2 separate instances of absence as they are separated by an attendance.

The other thing I need to consider is rest days ("R") as these should not be considered as a break in absence ("S" on friday, "R" on Saturday & Sunday, "S" on monday will count as one period of absence).

I hope that helps clarify what my problem is :)

Thanks,
 
Upvote 0
woof, try the file in DropBox. Essentially, I broke it down to each section so it is as simple as possible. That is, one single formula in a cell, or as few formulas in a cell as possible. Instead of a ton of IF statements in one cell. Then, build upon each section, then consolidate the answer in the summary section. the R and S was not too hard. But the R-only and not counting the R made it more difficult. the formulas go to row 2200. Each different section is based on a relative reference, starting in row 11. Hope it helps. HRSW_xlsx_.xlsx
 
Upvote 0
Solution
woof, try the file in DropBox. Essentially, I broke it down to each section so it is as simple as possible. That is, one single formula in a cell, or as few formulas in a cell as possible. Instead of a ton of IF statements in one cell. Then, build upon each section, then consolidate the answer in the summary section. the R and S was not too hard. But the R-only and not counting the R made it more difficult. the formulas go to row 2200. Each different section is based on a relative reference, starting in row 11. Hope it helps. HRSW_xlsx_.xlsx
Thank you so much!!

I never would have got that :) Really appreciate your help!
 
Upvote 0
So I've been playing around with your idea to fit it in to my spreadsheet and followed the same logic to come up with this which does all I need it to :) Thanks again for your help!

Book1 (1).xlsx
BCDEFGHIJKLMNOPQRST
1Sick
2
3NameTotal "S" daysSeparate "S" instances20/1221/1222/1223/1224/1225/1226/1227/1228/1229/1230/1231/1201/0102/01
4Emp 172RRSSSHRRRRSSSS
5Emp 261SSRRRRSSSSRRRR
6Emp 343SHRRRRSSwSRRRR
7Emp 432SWRRRRSSWWRRROT
8Emp 561RSSSSSRRSWWWWR
9Emp 631HHRRRRWSSSRRRR
10
11
12
13Overwrite rest break to create continuous "S" period
14S
15Emp 1  SSS     SSSS
16Emp 2SSSSSSSSSSSSSS
17Emp 3S     SS SSSSS
18Emp 4S     SS      
19Emp 5 SSSSSSSS     
20Emp 6       SSSSSSS
21             
22
23Take first date
24Emp 12  1       1   
25Emp 211             
26Emp 331     1  1    
27Emp 421     1       
28Emp 51 1            
29Emp 61       1      
30
31
Sheet1
Cell Formulas
RangeFormula
D4:D9D4=COUNTIF(G4:T4,$D$14)
E4:E9E4=D24
H15:T21H15=IF(H4=$D$14,H4,IF(AND(G15=$D$14,H4="R"),$D$14,""))
G15:G20G15=IF(G4=$D$14,G4,"")
G24:G29G24=IF(G15="","",1)
H24:T29H24=IF(AND(H15<>"",G15<>""),"",IF(H15<>"",1,""))
D24:D29D24=SUM(G24:T24)
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,385
Members
448,956
Latest member
JPav

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top