Home » excel » excel – Display [h]:mm numberformat with comma separator for thousands of hours

excel – Display [h]:mm numberformat with comma separator for thousands of hours

Posted by: admin May 14, 2020 Leave a comment

Questions:

Is there a way of formatting a value to display hours and minutes with the ThousandsSeparator to improve readability on a large count of hours?

e.g. if I have a value of

1771.95

which displays as

42526:48

(using [h]:mm)

Can I get this to display as

42,526:48

without actually manipulating the value in the cell?

How to&Answers:

Possible work around

Though there’s no way to modify numberformats directly to display the ThousandsSeparator in hour values , you might consider using comments instead:

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim cell As Range, info$, temp
    For Each cell In Target
        On Error GoTo OOPS
        Application.EnableEvents = False
        Select Case cell.Value2
            Case Is > 1000
                cell.ClearComments
                temp = Split(Format(cell.Value2, "hh:mm"), ":")
                info = Format(Int(cell) * 24# + _
                       Int((cell - Int(cell)) * 24#), _
                       "#" & Application.ThousandsSeparator & "##0") & _
                       Application.ThousandsSeparator & _
                       temp(1) & " hours"
                cell.AddComment info
        End Select
OOPS:
        Application.EnableEvents = True
        On Error GoTo 0
    Next cell
End Sub

Example result

1771.95 displaying comment as 42,526.48 hours