I am converting minutes to [H]:mm (thank you DaveR (UK) for this part)
The formula bar shows:
1/1/1900 11:51:00
The cell contains:
35:51
Is there a way to convert the 35:51 to a string and not time?
(changing the cell format to general after the 35:51 is placed gives "1.49375" which is the time in its raw format)
Code
Sub test_time_2_String()
Dim a As Variant
Dim b As Integer
Dim c As Variant
Dim d As String, e As String, F As String
Cells(10, 21).Activate ' Arbitrary cell
' Break it down to its smallest parts in order to watch the progression
a = 2150.533333 ' this is 2150.533333 minutes
b = a ' b = 2150 (b = integer)
c = b / 60 ' c = 35.8333333
d = Int(c) ' d = "35" [hours]
e = Int(c - Val(d)) * 60 ' e = .833333 * 60 = "51" [minutes]
F = d & ":" & Format(e) ' use format so "35:51" isn't "35: 51"
ActiveCell.NumberFormat = "[h]:mm"
ActiveCell = F ' !! Need to convert this to string !!
end sub
Display More
I Dimmed d, e, & F as strings yet it still formats the cell as time as soon as it's pasted.
The ActiveCell.NumberFormat = "[h]:mm" line is there so a least I have 35:51 instead of 35:51:00. Neither General or Text formats worked.