excel - 显示 [h] :mm numberformat with comma separator for thousands of hours

标签 excel vba

有没有办法用 ThousandsSeparator 格式化一个值以显示小时和分钟?提高大量小时数的可读性?

例如如果我的值为

1771.95



显示为

42526:48



(使用 [h]:mm)

我可以让它显示为

42,526:48



没有实际操作单元格中的值?

最佳答案

可能的解决方法

虽然无法直接修改数字格式以显示 ThousandsSeparator在小时值中,您可以考虑使用注释:

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


示例结果
1771.95将评论显示为 42,526.48 hours

关于excel - 显示 [h] :mm numberformat with comma separator for thousands of hours,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58854992/

相关文章:

vba - Range.Validation方法发生1004错误

vba - ADO 库引用和向前兼容性

vba - Excel 宏识别今天是星期几

Excel Worksheet_Change 事件不起作用

python - 只读取某些列

r - 如何在 R 中复制 Excel 求解器

excel - Excel VBA 中出现 Double 类型溢出错误

excel - 复制粘贴 VBA 代码有空白行

excel - 你能让 Excel 公式迭代和计数循环吗

vba - 如何将 excel UsedRange 转换为从单元格 A1 开始其工作表(即删除 UsedRange 之外的所有空白行和列)?