Daxton A.
10-15-2004, 04:22 PM
:bink: My question is about the converting from minutes to a decimal answer. I have what I think would make it work but it won't work. I've been trying to get it to work for a couple of days now and thought I would rely on the experts to show me the answer. I started out making this timesheet as a way to teach VB to a friend of mine b/c he needs the timesheet and he wants to learn VB. Right in the middle of teaching him, lol i need some help. The error comes up
in the minHand function. I'm a little bit rusty on functions so it's probably just missing something.
I have the Timesheet attached in case it needs to be looked at.
Sub addTime()
Dim pm As Integer
Dim i As Integer
Dim theValue1 As Double
Dim theValue2 As Double
Dim theValue As Double
Dim theDecimal1 As Double
Dim theDecimal2 As Double
Dim theDecimal As Double
Dim mins1 As Integer
Dim mins2 As Integer
'range C & F is the Hour Hand
'range D & G is the Minute Hand
'range E & H is AM or PM
For i = 2 To 1000
mins1 = Range("D" & i).Value
mins2 = Range("G" & i).Value
If Range("C" & i) = "" Or Range("D" & i) = "" Or Range("E" & i) = "" Or Range("F" & i) = "" Or Range("G" & i) = "" Or Range("h" & i) = "" Then
i = 1000
Else
If Left(Range("K" & i).Formula, 4) = "=SUM" Then 'Or Range("K" & i) = ""
i = 1000
Else
If Range("E" & (i - 1)) = "PM" Then
theValue1 = Range("C" & i).Value + 12 & "." & minHand(mins1)
Else
theValue1 = Range("C" & i).Value & "." & minHand(mins1)
End If
If Range("H2") = "PM" Then
theValue2 = Range("F" & i).Value + 12 & "." & minHand(mins2)
Else
theValue2 = Range("F" & i).Value & "." & minHand(mins2)
End If
theValue = theValue2 - theValue1
Range("K" & i) = theValue
End If
End If
Next i
End Sub
Function minHand(minutes As Integer)
If minutes = 15 Then
minutes = 25
ElseIf minutes = 30 Then
minutes = 50
ElseIf minutes = 45 Then
minutes = 75
End If
End Function
in the minHand function. I'm a little bit rusty on functions so it's probably just missing something.
I have the Timesheet attached in case it needs to be looked at.
Sub addTime()
Dim pm As Integer
Dim i As Integer
Dim theValue1 As Double
Dim theValue2 As Double
Dim theValue As Double
Dim theDecimal1 As Double
Dim theDecimal2 As Double
Dim theDecimal As Double
Dim mins1 As Integer
Dim mins2 As Integer
'range C & F is the Hour Hand
'range D & G is the Minute Hand
'range E & H is AM or PM
For i = 2 To 1000
mins1 = Range("D" & i).Value
mins2 = Range("G" & i).Value
If Range("C" & i) = "" Or Range("D" & i) = "" Or Range("E" & i) = "" Or Range("F" & i) = "" Or Range("G" & i) = "" Or Range("h" & i) = "" Then
i = 1000
Else
If Left(Range("K" & i).Formula, 4) = "=SUM" Then 'Or Range("K" & i) = ""
i = 1000
Else
If Range("E" & (i - 1)) = "PM" Then
theValue1 = Range("C" & i).Value + 12 & "." & minHand(mins1)
Else
theValue1 = Range("C" & i).Value & "." & minHand(mins1)
End If
If Range("H2") = "PM" Then
theValue2 = Range("F" & i).Value + 12 & "." & minHand(mins2)
Else
theValue2 = Range("F" & i).Value & "." & minHand(mins2)
End If
theValue = theValue2 - theValue1
Range("K" & i) = theValue
End If
End If
Next i
End Sub
Function minHand(minutes As Integer)
If minutes = 15 Then
minutes = 25
ElseIf minutes = 30 Then
minutes = 50
ElseIf minutes = 45 Then
minutes = 75
End If
End Function