vba - 如何显示hh :mm:ss in Excel?

标签 vba excel time

我是 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

开始

enter image description here

结束

enter image description here

关于vba - 如何显示hh :mm:ss in Excel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30840170/

相关文章:

excel - 如何使用 VBA 中的 getelementsbyclassname 从在线零售商的网页上抓取产品名称和定价数据?

excel - 使用 Trim 功能删除不需要的多余字符

excel - 查找列标题、复制数据并将值粘贴到另一个工作簿中

python - time.sleep() 时的交互?

excel - 使用 Excel VBA 进行网页抓取

vba - 拆分( "TEXT", "+"或 "-",2)

excel - vba Excel数据连接

python - 从 excel 到 pandas df 的空单元格

ruby-on-rails - 在测试期间模拟当前日期

javascript - 时间是否在 Interval 内?