Trying to use a Macro to fix timesheet numbers for regular time and overtime.

zone709

Well-known Member
Joined
Mar 1, 2016
Messages
2,125
Office Version
  1. 365
Platform
  1. Windows
Hi, I have hours for the week from F to X. Y and Z i have formulas inside to add up the week. The thing is if someone goes over 40 hours for the week then they get the overtime.
If its under 40 hours for the week. Then nothing happens to that row and you can see below in results Mike stays the same.
What i am doing now is i have to go through each person and break it out. I would like maybe a macro to do this as there are so many more people. You can see in the results how i break it down starting with the first day. like Jeff on Tuesday is 8 and 2. Marco Monday 8 and 2 Tuesday 8 and 2. All the ST columns shouldn't go over 8. The rest goes into overtime for that day as long as Y is over 40. Once Y hits 40 that's it. Row stays the same.

In short version. I need to break each person out to get overtime as long as they go over 40 hours for the week. If not then that row stays the same. DT in yellow or not yellow doesn't get touched ever. it will always be blank. No one does double time. Any help would be great.

Sheet 1

Test.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAA
1MondayTuesdayWednesdayThursdayFridaySaturdaySundayWEEKLY TOTALS
2
3No.TradeIDJOBSTOTDTSTOTDTSTOTDTSTOTDTSTOTDTSTOTSTOTSTOTDT
41JeffSuper45152 23rd Street5.010.08.08.013.02.08.054.0--
52MarcoOperator63152 23rd Street10.010.09.06.08.04.047.0--
63MikeOperator121152 23rd Street6.08.06.08.05.033.0--
Data


Results

Results.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAA
1MondayTuesdayWednesdayThursdayFridaySaturdaySundayWEEKLY TOTALS
2
3No.TradeIDJOBSTOTDTSTOTDTSTOTDTSTOTDTSTOTDTSTOTSTOTSTOTDT
41JeffSuper45152 23rd Street5.08.02.08.08.08.05.02.03.05.040.014.0-
52MarcoOperator63152 23rd Street8.02.08.02.08.01.06.08.02.02.040.07.0-
63MikeOperator121152 23rd Street6.08.06.08.05.033.0--
Data
 

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.
Macro not required.
In Y4
Excel Formula:
=MIN(40,SUMPRODUCT($F4:$X4*($F$3:$X$3<>"DT")))
In Z4
Excel Formula:
=MIN(40,SUMPRODUCT($F4:$X4*($F$3:$X$3<>"DT")))
Both copied down.
 
Upvote 0
If you want the hours to break out automatically I'd suggest adding a block of columns (F-L in example show) where you enter the total hours for each day. Formulas can then calculate the standard time and overtime for each day and the weekly totals.

Book1
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAH
1Total HoursMondayTuesdayWednesdayThursdayFridaySaturdaySundayWEEKLY TOTALS
2
3No.TradeIDJOBMonTueWedThuFriSatSunSTOTDTSTOTDTSTOTDTSTOTDTSTOTDTSTOTSTOTSTOTDT
41JeffSuper45152 23rd Street5108813285 828 8 852 8 4770
52MarcoOperator63152 23rd Street101096848282816 8 4   4250
63MikeOperator121152 23rd Street686856 8 6 8 5     3300
Sheet1
Cell Formulas
RangeFormula
M4:M6M4=IF(F4="","",MIN(F4,8))
N4:N6N4=IF(F4>8,F4-8,"")
P4:P6P4=IF(G4="","",MIN(G4,8))
Q4:Q6Q4=IF(G4>8,G4-8,"")
S4:S6S4=IF(H4="","",MIN(H4,8))
T4:T6T4=IF(H4>8,H4-8,"")
V4:V6V4=IF(I4="","",MIN(I4,8))
W4:W6W4=IF(I4>8,I4-8,"")
Y4:Y6Y4=IF(J4="","",MIN(J4,8))
Z4:Z6Z4=IF(J4>8,J4-8,"")
AB4:AB6AB4=IF(K4="","",MIN(K4,8))
AC4:AC6AC4=IF(K4>8,K4-8,"")
AD4:AD6AD4=IF(L4="","",MIN(L4,8))
AE4:AE6AE4=IF(L4>8,L4-8,"")
AF4:AG6AF4=SUM(M4,P4,S4,V4,Y4,AB4,AD4)
AH4:AH6AH4=SUM(O4,R4,U4,X4,AA4,)
 
Upvote 0
Macro not required.
In Y4
Excel Formula:
=MIN(40,SUMPRODUCT($F4:$X4*($F$3:$X$3<>"DT")))
In Z4
Excel Formula:
=MIN(40,SUMPRODUCT($F4:$X4*($F$3:$X$3<>"DT")))
Both copied down.
Hi thanks for reply. Do i put each formula in Y and then Z. Both are returning 40?
 
Upvote 0
Hi thanks for reply. Do i put each formula in Y and then Z. Both are returning 40?
Hi ok thanks. I see what it does. It only changes Column Y and Z which is what i am looking for but i need the break outs in each column for ST and OT.

My data comes all into Column under ST.

So if its 10 or 11 and as long as Y is over 40 then i need to break it out like this 8 / 2 or 8 / 3.
The option response above from Myall is pretty close to what i need but i am trying to stay away from adding columns from F to L. Then run formulas. Reason i already have formulas pulling the numbers into ST only.
 
Upvote 0
i am trying to stay away from adding columns from F to L. Then run formulas. Reason i already have formulas pulling the numbers into ST only.
Without a macro you can’t put it in to a cell and then have that cell change. I.e. you can’t put 10 in a cell and have it change itself to 8 and carry over 2. Even with a macro it’s not advisable.
You could put the data entry table on the end- it doesn’t have to go in F to L. Or even on another tab. Excel has lots of real estate- you may as well use it.
 
Upvote 0
Without a macro you can’t put it in to a cell and then have that cell change. I.e. you can’t put 10 in a cell and have it change itself to 8 and carry over 2. Even with a macro it’s not advisable.
You could put the data entry table on the end- it doesn’t have to go in F to L. Or even on another tab. Excel has lots of real estate- you may as well use it.
I been thinking about this. I may make a macro step by step. Put the data entry table on another tab. Work the formulas for the results and so on. I will probably Record alot then Re write it.
 
Upvote 0
I been thinking about this. I may make a macro step by step. Put the data entry table on another tab. Work the formulas for the results and so on. I will probably Record alot then Re write it.
You don’t need a macro to do that - it can all be done with formulas. Just cut columns F to L from my response and paste them on another tab.
 
Upvote 0
Hi, I am testing the formulas and building the sheet. The first sheet below is the total numbers i get to start right.
The second sheet with the formulas does well but look at Wednesday. It goes 8 and 1. On the results sheet. I need it to just stay 9 because as you can see in the ST column this guy never went over 40 hours for the week. So technically he doesn't get Overtime. The total in the ST column should be 37 instead of 36 and 1. If its over 40 hours then yes that would be right. Anyway updating this formula so it works that way? thanks.


Test.xlsx
ABACADAEAFAGAHAIAJAKALAM
7NONameTradeIDJobMondayTuesdayWednesdayThursdayFridaySaturdaySunday
81JoeSuper12068968
Data


Results

Test.xlsx
FGHIJKLMNOPQRSTUVWXYZAA
5MondayTuesdayWednesdayThursdayFridaySaturdaySundayWEEKLY TOTALS
67/227/237/247/257/267/277/28
7STOTDTSTOTDTSTOTDTSTOTDTSTOTDTSTOTSTOTSTOTDT
86.0 8.0 8.01.06.0 8.0     36.01.0
Data
 
Upvote 0

Forum statistics

Threads
1,223,882
Messages
6,175,164
Members
452,615
Latest member
bogeys2birdies

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