有没有办法用 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/