关于VBA中的代码,用于在单独的列中进行解析

问题描述 投票:0回答:3

我的问题是你如何解析HH中给出的时间:MM:SS到HH和MM在VBA的不同列中?

excel-vba vba excel
3个回答
1
投票
  • 录制一个宏。
  • 然后使用公式Minute()Hour()来获得你需要的东西。
  • 就这些。

1
投票

使用常量数据列A,尝试:

Sub parser206()
    Dim r As Range
    For Each r In Columns(1).Cells.SpecialCells(2)
        arr = Split(r.Text, ":")
        r.Offset(0, 1) = arr(1)
        r.Offset(0, 2) = arr(2)
    Next r
End Sub

enter image description here


0
投票

另一种对我有用的方法如下:

Sub foo()
TextVar = Format(Sheet1.Cells(1, 1).Value, "hh:mm:ss") ' get the value from the cell and convert the value to the right format
varHours = Left(TextVar, 2) 'get the first two characters ie the Hours
varMinutes = Mid(TextVar, 4, 2) 'get the middle two characters ie the Minutes
varSeconds = Right(TextVar, 2) 'get the last two characters ie Seconds
MsgBox varHours & " " & varMinutes & " " & varSeconds
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.