VBA Run Time Error 51 tied to Excel 2003
Hi I experiencing an issue for an urgent item - this macro works fine in excel 2003 but pukes if run in excel 2010. I get a runtime error 51 and i think all i have to do is wrap the time_interval with something (ex. XX(time_interval) - but i don't know what xx is).The particular line that has an issue is:
Num_of_Cells = (end_time - Start_time) / Time_Interval
Can someone please help
Nooreen
____________________________________________________________________________________
Private Sub Submit_Hours_Click()
Dim Time_Interval As Date
Dim Quantity As Integer
Dim BeginDay As Date 'Beginning of Time Interval
Dim EndDay As Date 'End of Time Interval
Day_Number = Cells(2, 3) + 1 'The 1 compensates for the first column
If (Day_Number > 8) Or (Day_Number < 2) Then
MsgBox "There are only 7 days in week, please enter a value between 1 to 7", vbInformation
Exit Sub
End If
If (IsDate(Cells(2, 5) = True)) Then
MsgBox "The start time you've entered is not a valid format, please delete and re-type the time", vbInformation
Exit Sub
End If
If (IsDate(Cells(3, 5) = True)) Then
MsgBox "The end time you've entered is not a valid format, please delete and re-type the time", vbInformation
Exit Sub
End If
If (Cells(3, 5) < Cells(2, 5)) Then
MsgBox "Please enter an end time that is later than the start time", vbInformation
Exit Sub
End If
Start_time = Cells(2, 5)
end_time = Cells(3, 5)
Time_Interval = Cells(11, 1) - Cells(10, 1)
Num_of_Cells = (end_time - Start_time) / Time_Interval
num_of_slots = Cells(3, 6) 'Total number of intervals
BeginDay = Cells(10, 1)
EndDay = BeginDay + (Time_Interval * (num_of_slots - 1))
If (Start_time < BeginDay) Then
MsgBox "Please choose a Start Time within the time interval", vbInformation
Exit Sub
End If
If (Start_time > EndDay) Then
MsgBox "Please choose a Start Time within the time interval", vbInformation
Exit Sub
End If
If (end_time < BeginDay) Then
MsgBox "Please choose a End Time within the time interval", vbInformation
Exit Sub
End If
If (end_time > EndDay) Then
MsgBox "Please choose a End Time within the time interval", vbInformation
Exit Sub
End If
If (Cells(2, 6) = "Yes") Then
Quantity = Cells(3, 3)
Else
Cells(3, 3) = 1
Quantity = 1
End If
If (Cells(2, 5) < Cells(10, 1)) Then
MsgBox "The start time you have entered is not within the time frame you have set, Please change your start time.", vbInformation
Exit Sub
End If
For x = 10 To (num_of_slots + 10)
If Round(Start_time, [14]) = Round(Cells(x, 1), [14]) Then
Start_shift = x
end_shift = Start_shift + CInt(Num_of_Cells) - 1
Exit For
End If
Next x
For z = 10 To (num_of_slots + 10)
If z >= Start_shift And z <= end_shift Then
Cells(z, Day_Number) = Cells(z, Day_Number) + Quantity
End If
If z > end_shift Then
Exit For
End If
Next z
Cells(9, Day_Number) = Cells(9, Day_Number) + Quantity
Msg = "Data Entered!" ' Define message.
Style = vbQuestion ' Define buttons.
Title = "Data Entry Confirmation" ' Define title.
Response = MsgBox(Msg, Style, Title)
If Response = vbOK Then ' User chose ok
End If
End Sub
Recent comments
5 years 36 weeks ago
6 years 22 weeks ago
6 years 34 weeks ago
6 years 37 weeks ago
6 years 38 weeks ago
6 years 43 weeks ago
6 years 52 weeks ago
7 years 2 days ago
7 years 3 days ago
7 years 3 days ago