在单元格中声明数值是小时
我想在一个单元格中声明一个特定的值是一个小时。 例如,我在一个单元格中有24个,我想要24小时。
这样我可以使用公式来计算新的date和时间。
我有一个我需要直接使用几个小时的号码列表。
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
试试这个vba。 select组并运行:
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
select你想要处理的单元格并运行这个短的macros:
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,请改用此macros:
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
如果你想把它当作一个时间值,为什么不把它作为一个时间值呢? 如果是一次性操作,则可以使用“select性粘贴”将整个单元划分为24,也可以使用=RC[-1]/24
创build另一列。
以天为单位存储值的优点是,使用数字格式[h]
,格式会正确,此外,您可以简单地将值相加或将其添加到date字段中。