简体   繁体   English

Excel时间功能转VBA功能

[英]Excel Time Function to VBA function

I have this number - 2411 [put in cell A2], which is the number of seconds since the start of an activity. 我有这个数字-2411 [放入单元格A2],这是自开始活动以来的秒数。 Now I know the start time of the activity which is 07/30/2016 13:11:18. 现在我知道该活动的开始时间是07/30/2016 13:11:18。 In excel if I want to convert this seconds to time, I can use this formula - Time(13,11,(18+A2)), which will return - 1:15 PM. 在excel中,如果我想将秒转换为时间,则可以使用以下公式-Time(13,11,(18 + A2)),该公式将返回-下午1:15。 I have close to 1500 lines of such numbers, and I know I can apply this formula and drag it till the end to get the details. 我有将近1500行这样的数字,我知道我可以应用此公式并将其拖动到最后以获取详细信息。 In VBA do we have a code which can do the same function? 在VBA中,我们有可以执行相同功能的代码吗?

Thanks. 谢谢。

You can use the Record Macro button for Excel to generate the VBA code based on your actions. 您可以使用Excel的“记录宏”按钮根据您的操作生成VBA代码。

The shorter version can be something like 较短的版本可能像

Sub a()
    Range("B2:B1500").Formula = "=Time(13,11,(18+A2))"
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM