Count the number of columns used in Excel for a Specific text

FWCRichardCoram

New Member
Joined
May 19, 2014
Messages
3
Hi there,

I am hoping for a simple solution to a formula i have been trying to get right.
I am trying to sum the number of "Leave" Days off a Microsoft Shifts roster export. I think i am close using the COLUMNS and COUNTIF Function but i cant get it right.
The problem with the export is if a staff member has more than one consecutive days leave it merges the cells into one.
I am trying to simply count how many days leave they have had in a range.

Below is screen grab of my spreadsheet with COLUMN D being where i need the formula.
Cells F8:I8 are merged

=COUNTIF(COLUMN(E8:I8,"Leave"))???

Any help would be greatly appreciated

1653128430260.png
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Few chances using stanfard functions, much better using a Customized one
1) Insert this code into a standard module of your vba project:
VBA Code:
Function CountInRange(ByRef myRan As Range, ByVal myVal) As Long
Dim iCnt As Long, myC As Range
'
myVal = UCase(myVal)
For Each myC In myRan
    If UCase(myC.MergeArea.Cells(1, 1).Value) = myVal Then
        iCnt = iCnt + 1
    End If
Next myC
CountInRange = iCnt
End Function

2) Now if you go to your worksheet, you can use in D4 the formula
Excel Formula:
=CountInRange(E4:J4,"leave")

Copy down as needed
 
Upvote 0
Solution

Forum statistics

Threads
1,214,891
Messages
6,122,105
Members
449,066
Latest member
Andyg666

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