Countif only one per row

janarthenan

New Member
Joined
Jun 11, 2016
Messages
22
Hi All

I have been trying to achieve the following for days now and can't seem to figure out a way.

I have a spreadsheet with dates when a supervision is done for a particular staff.

I am trying to have a weekly report so that I know on that particular week what my supervision Percentage was.

Every staff needs their supervision done at least every 3 months.

When I do the COUNTIF and if some one had their supervision twice (one in April and one in June) on the June calculation it counts it as 2.

NameAprilMayJuneJulyAugustSeptOctNovDecLast SupervisionNext Supervision
A1/4/171/6/171/7/17=MAX(B2:J2)=H2+90
B1/5/171/8/17=MAX(B3:J3)=H3+90
C....
D
E
F

<tbody>
</tbody>

When I do COUNTIF(B2:J2, "<="&1/4/17) - I get 1
When I do COUNTIF(B2:J2, "<="&1/7/17) - I get 3 (Which is correct) but I want this to be one.
- So basically I want the calculation to count the highest value only per row and If that highest value meets the COUNTIF condition to come back as 1.

Prefer if no VBA was used.

Regards
J
 
Peter!

You are a LEGEND!

Thanks - it does exactly what I needed.

Thank You for your patience I really appreciate it!

God Bless
Jan
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
You are very welcome. Glad it worked for you. :)
 
Upvote 0
Hi Peter

Could I be a pain again.

Your code works great, I was just wondering if you will be able to add something to it.

I tried to tweak the code, but I am not that advanced to do something.

I would like the Count_Rows to ignore a row if there is a value in a particular column.

For Example:

NAMEDateDateDateLeaver
A10/2/17
B10/3/17
C5/2/175/2/17Resigned

<tbody>
</tbody>

I need count_rows to ignore Row C when there is a value in the Leaver Column.

Thank You,

Jan
 
Upvote 0
Can't think of any way but the long way:

=IF(COUNTIFS($B$2:$N$2,">"&D14-90,$B$2:$N$2,"<="&D14)>0,1,0)+IF(COUNTIFS($B$3:$N$3,">"&D14-90,$B$3:$N$3,"<="&D14)>0,1,0)+IF(COUNTIFS($B$4:$N$4,">"&D14-90,$B$4:$N$4,"<="&D14)>0,1,0)+IF(COUNTIFS($B$5:$N$5,">"&D14-90,$B$5:$N$5,"<="&D14)>0,1,0)+IF(COUNTIFS($B$6:$N$6,">"&D14-90,$B$6:$N$6,"<="&D14)>0,1,0)+IF(COUNTIFS($B$7:$N$7,">"&D14-90,$B$7:$N$7,"<="&D14)>0,1,0)+IF(COUNTIFS($B$8:$N$8,">"&D14-90,$B$8:$N$8,"<="&D14)>0,1,0)+IF(COUNTIFS($B$9:$N$9,">"&D14-90,$B$9:$N$9,"<="&D14)>0,1,0)

Not very versatile as it will not update nicely if a new supervisee is added.
 
Upvote 0
Peter

Yes Its exactly the same data. The Leaver is Column Q.
If Possible Count_Rows to add a rule to ignore if any value is present in the leavers column.

Regards
Jan
 
Upvote 0
Try the UDF below. For the layout in post 10 with the additional 'Leaver' column in column Q, use it like this

=Count_Rows_With_Ignore(B$3:N$10,D14,$Q$3:$Q$10)

Code:
Function Count_Rows_With_Ignore(RngToLookIn As Range, DateToCheck As Date, rngIgnore As Range) As Long
  Dim aRangeToLookIn As Variant, aIgnore As Variant
  Dim EarlierDate As Date
  Dim i As Long, j As Long
  
  aRangeToLookIn = RngToLookIn.Value
  aIgnore = Intersect(RngToLookIn.EntireRow, rngIgnore.EntireColumn).Value
  EarlierDate = DateAdd("d", -90, DateToCheck)
  'EarlierDate = DateAdd("m", -3, DateToCheck)
  For i = 1 To UBound(aRangeToLookIn, 1)
    If IsEmpty(aIgnore(i, 1)) Then
      For j = 1 To UBound(aRangeToLookIn, 2)
        If aRangeToLookIn(i, j) <= DateToCheck Then
          If aRangeToLookIn(i, j) >= EarlierDate Then
            Count_Rows_With_Ignore = Count_Rows_With_Ignore + 1
            Exit For
          End If
        End If
      Next j
    End If
  Next i
End Function
 
Upvote 0
Hi Peter

That sortof works.

The problem is that the Leaver column contains a VLOOKUP formula, so I have to physically delete each "empty" value for the equation to work.

Jan
 
Upvote 0
Again Peter

You have delivered!!

I was trying IsBlank - but realised its a WS formula, not suitable for VBA.

Thanks

Jan
 
Upvote 0

Forum statistics

Threads
1,215,398
Messages
6,124,694
Members
449,179
Latest member
kfhw720

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