我想在单元格中声明一个特定的值是一小时。例如,我在一个单元格中有24个,我希望将其视为24小时。
这样我可以使用公式来计算新的日期和时间。
我有一个我需要直接使用数小时的数字列表。
24 - Need to represent as 24 hours
13 - Need to represent as 13 hours
14 - Need to represent as 14 hours
6 - Need to represent as 6 hours
8 - Need to represent as 8 hours
答案 0 :(得分:2)
选择您要处理的单元格并运行此短宏:
Sub HourByHour()
Dim r As Range
For Each r In Selection
If r.Value <> "" And IsNumeric(r) Then
r.Value = TimeSerial(r.Value, 0, 0)
r.NumberFormat = "h"
End If
Next r
End Sub
修改#1:强>
要将24显示为24,请改用此宏:
Sub HourByHour()
Dim r As Range
For Each r In Selection
If r.Value <> "" And IsNumeric(r) Then
r.Value = TimeSerial(r.Value, 0, 0)
r.NumberFormat = "[h]"
End If
Next r
End Sub
答案 1 :(得分:2)
试试这个vba。选择该组并运行:
Sub hr()
Selection.NumberFormat = "[hh]:mm:ss"
Selection.Value = ActiveSheet.Evaluate("INDEX(INT(" & Selection.Address(0, 0) & "/24)+TIME(" & Selection.Address(0, 0) & ", 0, 0),)")
End Sub
对于公式版本:
在空栏中:
=INT(A1/24)+Time(A1,,)
并复制下来。然后将值复制并粘贴到所需的列上,并格式化该列[hh]:mm:ss
答案 2 :(得分:2)