COUNTIF for a variable range?

Fritz24

Board Regular
Joined
Sep 8, 2004
Messages
102
I need to create a formula that displays how many days a person has worked in a month, for the month to date. I'm getting my data from someone elses's spreadsheet (example below) so I can't really go in and change it as I'd like. Sample data from the spreadsheet:
Copy of New Scheduler Jan 05.xls
CDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAK
8D/O12.00-8.00D/O12.00-4.0012.00-8.009.00-5.00D/O8.00-4.008.00-4.008.00-4.008.00-4.008.00-4.00D/OD/O12.00-8.0012.00-8.00D/OholsholsholsD/O8.00-4.008.00-4.008.00-4.008.00-4.008.00-4.00D/OD/O9.00-5.008.00-4.308.00-4.309.00-5pmD/O1313
9D/OholsD/OholsholsholsD/Ohols8.00-4.008.00-4.008.00-4.008.00-4.00D/OD/O8.00-4.008.00-4.00D/O8.00-4.008.00-4.008.00-4.00D/O8.00-4.008.00-4.00holsholsholsD/OD/Ohols8.00-4.308.00-4.309.00-5pmD/O77
10D/OsickD/OsicksicksickD/OsicksicksicksicksickD/OD/OsicksickD/OsicksicksickD/OsicksicksicksicksickD/OD/Osick8.00-4.308.00-4.309.00-5pmD/O00
11D/O12.00-8.00D/Osick12.00-8.009.00-5.00D/O8.00-1.00holssick8.00-4.008.00-4.00D/OD/O12.00-8.00D/O12.00-8.0012.00-8.0012.00-8.009.00-5.00D/O8.00-4.00hols8.00-4.008.00-4.008.00-4.00D/OD/O9.00-5.008.00-4.308.00-4.309.00-5pmD/O1212
FULL TIMERS


Doing a COUNTIF of ("*-*") gives me the number of days worked for the whole month. However I need it for MTD. I've tried to build in a formula that uses NETWORKDAYS to calculate the figure, but if someone has holidays booked later in the month than today's date then it doesn't work.

Row 9 is an example. The total days worked should be 11 but my calculation has it as 7.

Any ideas on how I can get round this?
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi Fritz,

Given your present layout, with day 1 in col C and 33 ??? days to col AI put this formula in AJ8 and copy down: =COUNTIF($C8:INDIRECT("RC"&DAY(TODAY())+2,0),"*-*")

HTH
 
Upvote 0
Did you mean -2 and not +2? When I use -2 it works, but for some reason not on all the columns. The calculation should actually be in column AF. I had a couple of hidden columns in the example I posted. I have taken them out though and it's still not working quite right.
 
Upvote 0
Hi Fritz,

Which columns are hidden? Do you mean cols A & B? Your example shows cols C continuously through to AI, although in AI you always have D/O which I assumed meant Day Off. If column C has day 1 of the month then column AI becomes day 33!!

Because your day 1 starts in column 3 day n will occur in column n+2 hence the +2. Taking today as an example day 26 falls in column AB which if you change to R1C1 reference style (Tools > Options > General tab > settings) you will see is column 28. Thus the column no. is two greater than the day No.

HTH
 
Upvote 0
Columns AF - AI were hidden. They just contained other calculations I've been trying. The range of data I'm looking at is in columns C - AE.

Columns A and B just contain the employee's name and number and are not part of the calculation.
 
Upvote 0
If you delete columns A&B such that day 1 falls in column A and put your formula in column AF it becomes: =COUNTIF($A8:INDIRECT("RC"&DAY(TODAY()),0),"*-*")
 
Upvote 0
I can't really delete the columns as it's not my spreadsheet. What should the formula be if it lived in column AF with columns A and B still there?
 
Upvote 0
Well now I've just tried the formula again using -1 and it works fine!

Thanks for all your help with this.
 
Upvote 0
Hi,

If you have to keep cols A & B then the formula should be as I gave you. However, you say your date range is from col C to AE -- that's only 29 days! the formula will only work if you have one day per column.

If day 1 is in col C day 31 will be in Col AG (check it - put a row of numbers across the top with 1 in col C.) The formula can go in col AH, AI, AK or wherever. The only thing to watch is the offset between Col 1 (i.e. col A) and day 1. In this case +2
 
Upvote 0
With + 1 (edit: NOT -1) it will give you results to yesterday, which maybe is what you want. I worked it to include today
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,251
Members
448,556
Latest member
peterhess2002

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