Counting # of Blocks of consecutive cells between given value

pd15101

New Member
Joined
Dec 17, 2017
Messages
2
Hi all,

Having a little drama with a roster redesign I'm doing.

Each employee has a row, 365 cells long, representing the entire year. Days off are marked "X", while days worked are filled with a numerical start time.

To ensure the employees are rostered as equally as possible, I would like a way to count the number of blocks of >7 consecutive shifts. What this means is the number of times there is at least 7 cells between two cells which contain "X".

The count is then used in a separate sheet to compare against other employees.

I've nutted out how to count the number of weekend shifts for my other analysis, but this one has me stumped.

Any help appreciated!
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hi,

as "X" is text and the time is a number, the function specialcells(2,1) = numbers and specialcells(2,2) = text the entries are distinguish.

Without testing then count of more than 7 shifts are:

Code:
iRow = 2
for each Ar in rows(iRow).specialcells(2,1).areas
      if Ar.count > 7 then iShifts = iShifts + 1
next Ar
msgbox "Number of shifts > 7: " & iShifts

regards
 
Upvote 0
Hi Fennek,

Thanks for the quick reply. I have only used the formula line before.

How do I use the code? Or, preferably, is there a way to do it using a formula?

Thanks again!
 
Upvote 0

Forum statistics

Threads
1,216,110
Messages
6,128,892
Members
449,477
Latest member
panjongshing

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