Converting decimal time to hours:minutes in VBA

JSA

New Member
Joined
Apr 9, 2011
Messages
22
I have looked and found many ways to do this but none are working within what code i do have

I need to convert a general number into hours:minutes within VBA code

Source info is in minutes. I have previously used TimeValue and Format to make it work but for some reason this time i cannot get it to give me anything other than 1900/1/1 12:00 AM or just 0

ATime is the time in minutes

The relevant code is

Dim ATime As String
Dim AName As String
Dim i As Integer

i=2
ATime = Sheet2.Cells(i, 14)

While AName <> ""
Sheet4.Cells(i, 3).Value = ATime / 60 ----here is where i need it to convert

i = i + 1

ATime = Sheet2.Cells(i, 14)
Wend

Any help would be greatly appreciated
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
It stands for Agent Name and is just another piece for datum and is assigned AName = Sheet2.Cells(i, 7)
 
Upvote 0
But it's not assigned in the loop, so the loop will repeat until i exceeds the number of rows, and then you'll get a run-time error.

To converts minutes to an Excel serial date, divide by 1440, not 60.
 
Upvote 0
There was more code in the loop, i just didnt want to clutter up the page so i removed it before posting as it didn't relate to the question

This problem has been bugging me for hours and I know i tried 1440 before but for some reason it didnt work.

Now entirely sure each iteration i used but this is what i ended up using

Sheet4.Cells(i, 3).Value = Format(ATime / 1440, "hh:mm")

Thanks for the help, it now works as intended
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,908
Members
452,949
Latest member
beartooth91

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top