我是 Excel VBA 新手。我想设置一个循环,在新单元格中显示每分钟的时间。
有没有办法只显示单元格中的时间 (hh:mm:ss),而不显示旁边的日期?另外,我希望显示时区。 (例如新加坡时间,“SGT”)。
这是我希望看到的输出示例:
23-Oct-13 10:00:00 AM SGT
23-Oct-13 10:01:00 AM SGT
23-Oct-13 10:02:00 AM SGT
23-Oct-13 10:03:00 AM SGT
23-Oct-13 10:04:00 AM SGT
23-Oct-13 10:05:00 AM SGT
23-Oct-13 10:06:00 AM SGT
23-Oct-13 10:07:00 AM SGT
23-Oct-13 10:08:00 AM SGT
23-Oct-13 10:09:00 AM SGT
23-Oct-13 10:10:00 AM SGT
23-Oct-13 10:11:00 AM SGT
23-Oct-13 10:12:00 AM SGT
23-Oct-13 10:13:00 AM SGT
23-Oct-13 10:14:00 AM SGT
23-Oct-13 10:15:00 AM SGT
23-Oct-13 10:16:00 AM SGT
23-Oct-13 10:17:00 AM SGT
23-Oct-13 10:18:00 AM SGT
23-Oct-13 10:19:00 AM SGT
23-Oct-13 10:20:00 AM SGT
...
最佳答案
这应该可以了,玩得开心。 :-)
Option Explicit
Sub test()
Dim i&, sTime As Date, TimeStep As Date, Cell As Range
'// Format range cell to 24Hrs
With Range("A1:A1440") '// 24H*60M
.NumberFormat = "HH:MM:SS;@"
End With
Set Cell = [A1] '// first cell to write
sTime = "00:00:00" '// start time
'// Loop 24hrs
TimeStep = "00:01:00" '// time increment
For i = 0 To 1439 ' // 1439 means 1439 cells
Cell.Offset(i, 0).Value = sTime
sTime = sTime + TimeStep
Next i
End Sub
开始
结束
关于vba - 如何显示hh :mm:ss in Excel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30840170/