VBA Solution To Find Position In A Series of Cells

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,616
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am being challenged with finding a VBA solution to do a particular task. I suspect that explaining the task will be more difficult than an actual solution. I will try my best, but if I neglect to share critical information please ask for clarification. I'm not entirely sure what all would be needed to assist in find a solution.

SOP Schedule.xlsm
ABWXYZ
21719-JulSun
21820-JulMonE211:00 AM7:00 PM8.00
21921-JulTueE211:00 AM7:00 PM8.00
22022-JulWedE211:00 AM7:00 PM8.00
22123-JulThuE211:00 AM7:00 PM8.00
22224-JulFriL14:00 PM12:00 AM8.00
22325-JulSatL14:00 PM12:00 AM8.00
22426-JulSunL14:00 PM12:00 AM8.00
22527-JulMonL14:00 PM12:00 AM8.00
22628-JulTue
22729-JulWed
22830-JulThu
22931-JulFriE211:00 AM7:00 PM8.00
23001-AugSatE17:00 AM3:00 PM8.00
MASTER


This represents an employee's schedule for one pay period. Shift legs of a pay period can be dynamic. In this case its 1 day off, 8 on, 3 off, 2 on. It could be any combination of legs, but never less than 1 day off in succession. (the single day off at the beginning of the payperiod tags onto a day off at the end of the previous pay period.

What I need to do is deterine what number within the series of days off a particular day off represents. In this example, Jul 28 is position 1, July 29th is position 2 and position 3 is Jul 30th.

In my code, these blank positions (day's off) could be days that the employee has been assigned to work (beyond the regular schedule). When this happens, the vacant cell in W is populated with a value of "RSO" and the columns X, Y and Z populated accordingly with the times of the shift.

As the rate of pay is determined by the day within the legs of worked shifts, I need to know the position within the span of days off that the RSO exists. So, if the employee worked on Jul 30th, W228 = RSO. I need to determine that the position value is 3.

Some considerations:
- There can be any number of days off between legs of scheduled shifts. The number of days within any scheduled leg is variable.
- The leg of days off could include dates in bordering pay periods. In this example for instance, Jul 19 is the start of a payperiod and represents position 3 of a three day leg that starts on Fri. Jul 17th of the previous pay period.
- There could be more than one "RSO" in a leg of days off. In this example, W226 could be RSO (position 1) and then W227 could be RSO (position 2).
- only one date is processed at a time, so there would be no need to determine both positions of RSO, just the one according to the particular date being processed the application.

I would be very grateful to anyone that is able to provide direction towards a solution. I am simply a novice VBA user, and am unfamiliar with the use of different tools available for this approach.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
you haven't specified where or how you want the answer. If I have understood the question you don't need VBA, try putting this formula into column AA2, and copy it down, put 0 in AA1
=IF(OR(W2="RSO",W2=""),AA1+1,0).
If you want a vba solution can you tell me how you want the results presented
 
Upvote 0
Hi offthelip, I do appreciate your solution. I think the worksheet formula option will be adequate, and so far seems to be providing the information I need. My sample was for 1 employee (at column W), but I have 56 others in the master schedule database that I will need to apply this formula to respectively. A little bit more work, and a bit larger database, but I think it will work.
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,209
Members
453,022
Latest member
RobertV1609

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