COUNTIF on different sheet and across a range of cells

Griff687

New Member
Joined
Nov 4, 2021
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hi everyone,
I have an attendance sheet that I want to count the number of cumulative days employees are off work, either on Holiday, Sick or Absent for any other reason.
The way the sheet denotes this is by entering either "H", "S" or "A" into the cell representing that day.
I've tried a number of COUNTIF's but none of them are giving me what I want - here's the latest attempt (notice that it refers to a range because I want info for the whole week):
{=COUNTIF('Sheet1'!$L49:$ML74,"=H")+COUNTIF('Sheet1'!$L49:$ML74,"=S")+COUNTIF('Sheet1'!$L49:$ML74,"=A")}
I've entered it as a normal formula and an Array (Ctrl+Shift+Enter) formula - the above gives me "26" but there are only 2 x H's, 1 x S and 1 x A - so the result should be 4.
Any help appreciated.
Cheers
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
I wouldn't recommend an array formula for this issue - that is not needed. Your formula without the curly brackets should work, but you don't need to use "=H" where "H" will suffice. Have you checked your data does not have trailing spaces which appears the same on screen, but is actually different? If you cannot find any such trailing (or leading) spaces, I recommend debugging line by line checking using something like =L49="H" (which returns TRUE/FALSE) copied down and across to see where you have mismatches, and repeat for S and A. I presume you intend to test both columns L & M - that seems unusual. It's hard to answer this 100% without seeing the data, but hopefully this will set you on the right track.
 
Upvote 0
Solution
Hi Andrew,
I created a smaller version of what I'm looking for so I could post a snippet of it for you - but the same formula on the same sheet is now giving the correct results???
The 8 in the yellow cell is what I'm after - the only thing that changed was the sheet ref and having the formula on the same sheet.
Any idea why it doesn't work with the formula on a different sheet - also, there are no spaces etc - the cells are a "data validation list" with W, H, S, A as the only selections available (same in the test Sheet2).
 

Attachments

  • Capture8.JPG
    Capture8.JPG
    70.8 KB · Views: 18
Upvote 0
Hi Andrew,
Sorry about this, but early morning eyes not working - the reference range should have been L49:M74 - I'd somehow got ML74 which is why it wasn't working :O(
Fool I am - sorry for wasting your time.
 
Upvote 0
Work off day count.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAH
1October-2021
2
3Date01-Oct-2102-Oct-2103-Oct-2104-Oct-2105-Oct-2106-Oct-2107-Oct-2108-Oct-2109-Oct-2110-Oct-2111-Oct-2112-Oct-2113-Oct-2114-Oct-2115-Oct-2116-Oct-2117-Oct-2118-Oct-2119-Oct-2120-Oct-2121-Oct-2122-Oct-2123-Oct-2124-Oct-2125-Oct-2126-Oct-2127-Oct-2128-Oct-2129-Oct-2130-Oct-2131-Oct-21Total Work Off
4Day NameFridaySaturdaySundayMondayTuesdayWednesdayThursdayFridaySaturdaySundayMondayTuesdayWednesdayThursdayFridaySaturdaySundayMondayTuesdayWednesdayThursdayFridaySaturdaySundayMondayTuesdayWednesdayThursdayFridaySaturdaySunday
5Employee1WWPPAPHWWPSPPPWWPPPPPWWPPPPPWWH14
6Employee2WWPPPPHWWPPPPPWWPSPPPWWPPPPPWWP12
7Employee3WWPAPPHWWPPPPAWWPPPPSWWPPPPPWWP14
8Employee4WWPPPPHWWPPAPPWWPPPPPWWPPPPAWWP13
9Employee5WWPPPPHWWPPPPPWWPPPPPWWPPSPPWWA13
10
11
12xl
13
14Column1Column2
15PresentP
16AbsentA
17HolidayH
Sheet1
Cell Formulas
RangeFormula
B4:AF4B4=B3
AH5:AH9AH5=COUNTIF(B5:AF5,"H")+COUNTIF(B5:AF5,"S")+COUNTIF(B5:AF5,"A")+COUNTIF(B5:AF5,"W")
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B5:AF9Cell Valuecontains "H"textNO
B5:AF9Cell Valuecontains "S"textNO
B5:AF9Cell Valuecontains "a"textNO
B5:AF9Cell Valuecontains "w"textNO
Cells with Data Validation
CellAllowCriteria
B5:AF9List=$B$15:$B$19
 
Upvote 0
I think your problem might be solved if you follow this method

Work off day count.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAH
1October-2021
2
3Date01-Oct-2102-Oct-2103-Oct-2104-Oct-2105-Oct-2106-Oct-2107-Oct-2108-Oct-2109-Oct-2110-Oct-2111-Oct-2112-Oct-2113-Oct-2114-Oct-2115-Oct-2116-Oct-2117-Oct-2118-Oct-2119-Oct-2120-Oct-2121-Oct-2122-Oct-2123-Oct-2124-Oct-2125-Oct-2126-Oct-2127-Oct-2128-Oct-2129-Oct-2130-Oct-2131-Oct-21Total Work Off
4Day NameFridaySaturdaySundayMondayTuesdayWednesdayThursdayFridaySaturdaySundayMondayTuesdayWednesdayThursdayFridaySaturdaySundayMondayTuesdayWednesdayThursdayFridaySaturdaySundayMondayTuesdayWednesdayThursdayFridaySaturdaySunday
5Employee1WWPPAPHWWPSPPPWWPPPPPWWPPPPPWWH14
6Employee2WWPPPPHWWPPPPPWWPSPPPWWPPPPPWWP12
7Employee3WWPAPPHWWPPPPAWWPPPPSWWPPPPPWWP14
8Employee4WWPPPPHWWPPAPPWWPPPPPWWPPPPAWWP13
9Employee5WWPPPPHWWPPPPPWWPPPPPWWPPSPPWWA13
10
11
12xl
13
14Column1Column2
15PresentP
16AbsentA
17HolidayH
18SickS
19Weekly OffW
Sheet1
Cell Formulas
RangeFormula
B4:AF4B4=B3
AH5:AH9AH5=COUNTIF(B5:AF5,"H")+COUNTIF(B5:AF5,"S")+COUNTIF(B5:AF5,"A")+COUNTIF(B5:AF5,"W")
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B5:AF9Cell Valuecontains "H"textNO
B5:AF9Cell Valuecontains "S"textNO
B5:AF9Cell Valuecontains "a"textNO
B5:AF9Cell Valuecontains "w"textNO
Cells with Data Validation
CellAllowCriteria
B5:AF9List=$B$15:$B$19
 
Upvote 0
Hi FMHasan,
Thanks for the info, but you'll see from the posts above yours that I'd already sorted it - down to a typo from me - had the range wrong, that's why it was giving incorrect results.
Thanks again though.
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,592
Members
449,089
Latest member
Motoracer88

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