sassriverrat
Well-known Member
- Joined
- Oct 4, 2018
- Messages
- 655
Hello-
I have two pieces of code, one recently and graciously written by a user. However, I seem to have an issue with it- I have a macro that creates, formats, and populates sheets. If I run the "sheet creator" macro with these two pieces of codes, then the militarytotime debugs on the red line below. If I disable the militarytotime function (just using apostrophes) and then re-enable it after the sheet is created, it works perfectly. I've also noted that this issue only lies if the variable is 0 (i.e. there was nothing in the reference cell (=militarytotime(A1)) when the sheet was created. If the reference cell was not blank, then the macro runs smoothly and all is well.
But yes, reference cell is blank and the macro bugs out before it can finish creating the sheet.
Ideas?
I have two pieces of code, one recently and graciously written by a user. However, I seem to have an issue with it- I have a macro that creates, formats, and populates sheets. If I run the "sheet creator" macro with these two pieces of codes, then the militarytotime debugs on the red line below. If I disable the militarytotime function (just using apostrophes) and then re-enable it after the sheet is created, it works perfectly. I've also noted that this issue only lies if the variable is 0 (i.e. there was nothing in the reference cell (=militarytotime(A1)) when the sheet was created. If the reference cell was not blank, then the macro runs smoothly and all is well.
But yes, reference cell is blank and the macro bugs out before it can finish creating the sheet.
Ideas?
Code:
Function Miltime(T1 As Integer)' Input T1: 24-hour time as integer,e.g., 1130=11:30, 1650=16:50
' Output, time as serial time e.g, 0.5 for noon.
Dim TT1 As Double
TT1 = Int(T1 / 100) + (((T1 / 100) - Int(T1 / 100)) / 0.6) '23.50
TT1 = TT1 / 24
Miltime = TT1
End Function
Function MilitarytoTime(Miltime As String) As Date
MilitarytoTime = Format(Replace(Miltime, ":", ""), "00:00")
End Function