I have time represented by a decimal number that I need to convert to minutes and seconds in Excel using VBA.
Example:
The number before the decimal point gives the minutes as 0.197683577 (0 minutes)
and the number multiplied by 60 gives the seconds = 0.197683577*60 = 11.86101462 (12 seconds)
= 0:12
I know I could do this by copying and pasting into text format and separating the number to the left and right using text to columns of the decimal point and then add “:” in between but there must be a way to calculate this.
The VBA function didn’t work for me but I found a workaround within Excel:
Where
W11is time in the form of a decimal number like900.3201306.The result is in minutes
15:00Basically, you take the truncated decimal minutes minus the decimal minutes+seconds to give you seconds only. Then you take the
decimal seconds * 60to give youseconds+milliseconds. Round this to give you seconds. If seconds are 0 then write “00” to get the correct format. Then add the truncated minutes plus the seconds.This formula seems to be working.