Formula for changing minutes to hours and minutes

CatRoberts

New Member
Joined
Mar 29, 2016
Messages
48
Hi all,

I'm trying to add a formula to my workbook to convert minutes to hours and minutes, so 120 to read 2:00 for example.

I've used a couple of different formulas: =X6/1440 and format [h]:mm and also =X6/(24*60) then format the cell as [hh]:mm

Every time I enter the formula into the cell X6, firstly I get a circular reference error, then it changes the formula to read: 29/04/1900 00:00:00 so my return is - 2880:02

I tried putting the formula into a different cell to remove the circular reference error but it's still changing the formula to 29/04/1900 00:00:00 when I press save.

I have no idea what I'm doing wrong?

Any advice?

Many thanks

Cat
 
The Application.EnableEvents = False was above the IF statement that exits the sub so if the statement was true then it would exit the sub with Events set as False.
 
Upvote 0

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
many thanks - a good catch and avoids hours of frustration!
 
Upvote 0
Sorry, major issue with what I posted,
Run the code below if you have run the previous code (it only needs running this once)
VBA Code:
Sub resetEvt()
   Application.EnableEvents = True
End Sub

then you can use the code below

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
    Application.EnableEvents = False
    If Target.Address = "$X$6" Then
        Target.Value = Target.Value / 60 / 24
        Target.NumberFormat = "[hh]:mm"
    End If
    Application.EnableEvents = True
End Sub


Mark! You're a genius! It works and I even managed to add and run it.

Is it difficult now to apply it to other cells in the sheet? I'd like it to work for:

X6:X16
Y6:Y16
Z6:Z16
AA6:AA16
AB6:AB16
AC6:AC16

Would I re-create this code for each individual cell and add it in? or is there a simpler way?

Thanks again

Cat
 
Upvote 0
Try...
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
    Application.EnableEvents = False
    If Not Intersect(Target, Range("X6:X16,Y6:Y16,Z6:Z16,AA6:AA16,AB6:AB16,AC6: AC16")) Is Nothing Then
        Target.Value = Target.Value / 60 / 24
        Target.NumberFormat = "[hh]:mm"
    End If
    Application.EnableEvents = True
End Sub
 
Upvote 0
Try...
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
    Application.EnableEvents = False
    If Not Intersect(Target, Range("X6:X16,Y6:Y16,Z6:Z16,AA6:AA16,AB6:AB16,AC6: AC16")) Is Nothing Then
        Target.Value = Target.Value / 60 / 24
        Target.NumberFormat = "[hh]:mm"
    End If
    Application.EnableEvents = True
End Sub



Yaaaaaaay!!!! Thank you so much, It works!
 
Upvote 0
You're welcome (please note that shouldn't be a space between AC6: and AC16).
 
Upvote 0

Forum statistics

Threads
1,214,884
Messages
6,122,082
Members
449,064
Latest member
MattDRT

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