LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
RPW RPW is offline
external usenet poster
 
Posts: 52
Default Looping problem

Hi all,

I need to calculate straight-time, overtime, and doubletime hours for a two
week period (for each worker). The rules a Anything over 12 hours in a
day is doubletime. Anything over 8 hours in a day is overtime AND anything
over 40 hours in a week is overtime.

I have a worksheet with several rows (one per worker) and columns (one for
each day of the two week period). The sub successfully and accurately
calculates straight, over, and doubletime for the first row only. I need to
know how to change the sub so that the range changes to the next row for each
row that has entries.

Thanks in advance for any help provided. Here's the code:

Dim st As Long, ot As Double, dt As Double, AccST1 As Double
Dim AccOT As Double, AccDT As Double, AccST2 As Double
Dim wks As Worksheet
Dim Workers As Variant, Week1 As Variant, Week2 As Variant
Dim WorkerCounter As Long, Wk1Counter As Long, Wk2Counter As Long
Dim Rg2Add1 As Range, Rg2Add2 As Range, cell As Range
Dim CellValue

Set wks = Worksheets("Daily Hours VB Test")
Workers = Array("a4:a29")
Week1 = Array("b4:h4")
Week2 = Array("i4:o4")

For WorkerCounter = LBound(Workers) To UBound(Workers)
On Error Resume Next
For Wk1Counter = LBound(Week1) To UBound(Week1)
Set Rg2Add1 = wks.Range(Week1(Wk1Counter))
For Each cell In Rg2Add1.Cells
CellValue = cell.Value
If CellValue 12 Then
dt = CellValue - 12
ot = 4
st = 8
ElseIf CellValue 8 Then
ot = CellValue - 8
st = 8
ElseIf CellValue <= 8 Then
st = CellValue
End If
If AccST1 + st <= 40 Then
AccST1 = AccST1 + st
AccOT = AccOT + ot
AccDT = AccDT + dt
Else
ot = AccST1 + st - 40
AccST1 = 40
AccOT = AccOT + ot
AccDT = AccDT + dt
End If
st = 0
ot = 0
dt = 0
Next cell
Next Wk1Counter
wks.Cells(WorkerCounter + 4, 17) = AccST1
For Wk2Counter = LBound(Week2) To UBound(Week2)
Set Rg2Add2 = wks.Range(Week2(Wk2Counter))
For Each cell In Rg2Add2.Cells
CellValue = cell.Value
If CellValue 12 Then
dt = CellValue - 12
ot = 4
st = 8
ElseIf CellValue 8 Then
ot = CellValue - 8
st = 8
ElseIf CellValue <= 8 Then
st = CellValue
End If
If AccST2 + st <= 40 Then
AccST2 = AccST2 + st
AccOT = AccOT + ot
AccDT = AccDT + dt
Else
ot = AccST2 + st - 40 + ot
AccST2 = 40
AccOT = AccOT + ot
AccDT = AccDT + dt
End If
st = 0
ot = 0
dt = 0
Next cell
Next Wk2Counter
wks.Cells(WorkerCounter + 4, 18) = AccST2
wks.Cells(WorkerCounter + 4, 19) = AccST2 + AccST1
wks.Cells(WorkerCounter + 4, 20) = AccOT
wks.Cells(WorkerCounter + 4, 21) = AccDT
st = 0
ot = 0
dt = 0
AccST1 = 0
AccST2 = 0
AccOT = 0
AccDT = 0
Next WorkerCounter

End Sub
--
rpw
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Looping Problem ryguy7272 Excel Programming 5 April 5th 07 01:41 AM
Looping Problem GregR Excel Programming 0 September 26th 06 04:29 PM
Looping problem........ Steve Jones Excel Programming 1 September 22nd 06 04:31 PM
Looping problem Sleeping Bear Excel Programming 2 July 7th 05 07:41 PM
If Then Else looping problem Kieran1028[_12_] Excel Programming 1 November 11th 04 06:27 PM


All times are GMT +1. The time now is 06:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"