UDFs for rotas

mole999

Well-known Member
Joined
Oct 23, 2004
Messages
10,524
Office Version
  1. 2019
  2. 2016
  3. 2013
Platform
  1. Windows
I've been trying to figure out something for work, initially to break down the component parts with formulas and then produce a result.

It finally dawned on me i might be better off writing a UDF for simplicity, and then I hit the snag I don't know enough about them to even start a small one (A good reference guide would be useful if you know of one)

The data



I need to look at the day and use that in the function, also the two percentage enteries, and for each cell take the string value, change to time values, so I can return a decimal hours between the highest / lowest (even across midnight)

I started with (which is rubbish)
Code:
Public Function Section2(rng As Range)
'Public Function Section2(start_time As String)
'Public Function Section2(DayValue As String, StartTime As String, EndTime As String)
'DayValue =
Dim Starttimetime As Date
Dim Endtimetime As Date
'Dim starttime
Dim endtime
start_time = Left(start_time, 4)
endtime = Right(endtime, 4)
Starttimetime = TimeValue(start_time)
Endtimetime = TimeValue(endtime)
End Function

can someone just fix the first part so that the values are drawn into the output cell, and I have day and percentages available in code to work from
 
It seems better to unpivot the table and split the times into separate columns (you can still have the original as an entry form). Then calculate the special conditions like:


Excel 2010
ABCDEFG
1WeekColumnTime InHoursAfter 8pm>50%?6pm-2am hours
21Mon0.2708330.5000
31Tue0.2708330.5000
41Wed0.2708330.5000
51Thu0.2708330.5000
61Fri0000
71Sat0000
81Sun0000
92Mon0000
102Tue0000
112Wed0000
122Thu0000
132Fri0.750.4583330.37510.33333333
142Sat0.750.4583330.37510.33333333
152Sun0.750.4583330.37510.33333333
163Mon0.750.4583330.37510.33333333
173Tue0000
183Wed0000
193Thu0000
203Fri0.2708330.5000
213Sat0.2708330.5000
223Sun0.2708330.5000
234Mon0000
244Tue0.750.4583330.37510.33333333
254Wed0.750.4583330.37510.33333333
264Thu0.750.4583330.37510.33333333
274Fri0000
284Sat0000
294Sun0000
305Mon0.3020830.5000
315Tue0.3020830.5000
325Wed0.3020830.5000
335Thu0.3020830.5000
345Fri0000
355Sat0000
365Sun0000
376Mon0000
386Tue0000
396Wed0000
406Thu0000
416Fri0.8020830.50.4687510.33333333
426Sat0.8020830.50.4687510.33333333
436Sun0.8020830.50.4687510.33333333
447Mon0.8020830.50.4687510.33333333
457Tue0000
467Wed0000
477Thu0000
487Fri0.3020830.5000
497Sat0.3020830.5000
507Sun0.3020830.5000
518Mon0000
528Tue0.8020830.50.4687510.33333333
538Wed0.8020830.50.4687510.33333333
548Thu0.8020830.50.4687510.33333333
558Fri0000
568Sat0000
578Sun0000
589Mon0.3229170.46875000
599Tue0.3229170.46875000
609Wed0.3229170.46875000
619Thu0.3229170.46875000
629Fri0000
639Sat0000
649Sun0000
6510Mon0000
6610Tue0000
6710Wed0000
6810Thu0000
6910Fri0.7916670.4583330.41666666710.33333333
7010Sat0.7916670.4583330.41666666710.33333333
7110Sun0.7916670.4583330.41666666710.33333333
7211Mon0.7916670.4583330.41666666710.33333333
7311Tue0000
7411Wed0000
7511Thu0000
7611Fri0.2916670.416667000
7711Sat0.343750.322917000
7811Sun0.2916670.333333000
7912Mon0000
8012Tue0.7916670.4583330.41666666710.33333333
8112Wed0.7916670.4583330.41666666710.33333333
8212Thu0.7916670.4583330.41666666710.33333333
8312Fri0000
8412Sat0000
8512Sun0000
8613Mon0.31250.354167000
8713Tue0.31250.354167000
8813Wed0.31250.354167000
8913Thu0.31250.354167000
9013Fri0000
9113Sat0000
9213Sun0000
9314Mon0000
9414Tue0000
9514Wed0000
9614Thu0000
9714Fri0.281250.5000
9814Sat0.281250.5000
9914Sun0.281250.5000
10015Mon0.281250.5000
Sheet5
Cell Formulas
RangeFormula
E2=MAX((C2+D2)-(20/24),0)
F2=--(IFERROR(E2/D2,0)>0.5)
G2=F2*MEDIAN(0,(C2+D2)-(18/24),0.33333333)


enhancing the bands and rolling sundays as needed.
 
Last edited:
Upvote 0

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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