将时间转换为分钟HH:MM:SS格式

时间:2022-08-23 16:31:45

I'm having a trouble converting a time in HH:MM:SS format to minutes. Here's my code;

我在将HH:MM:SS格式的时间转换为分钟时遇到了麻烦。这是我的代码;

For i = 2 To lastrow

    Sheets("RAW").Cells(i, 7).NumberFormat = "General"
    Sheets("RAW").Cells(i, lastcol) = Sheets("RAW").Cells(i, 7).Value * 1440

Next

My time looks like this: 00:40:38 The code always gives a Type Mismatch error. Any response would be appreciated.

我的时间看起来像这样:00:40:38代码总是出现类型不匹配错误。任何回应将不胜感激。

1 个解决方案

#1


0  

I believe the function you are looking for is TimeValue to get the time from a string:

我相信你正在寻找的函数是TimeValue来从字符串中获取时间:

Sheets("RAW").Cells(i, lastcol).Value2 = _
    Hour(TimeValue(Sheets("RAW").Cells(i, 7).Value2)) * 60 _
    + Minute(TimeValue(Sheets("RAW").Cells(i, 7).Value2))

#1


0  

I believe the function you are looking for is TimeValue to get the time from a string:

我相信你正在寻找的函数是TimeValue来从字符串中获取时间:

Sheets("RAW").Cells(i, lastcol).Value2 = _
    Hour(TimeValue(Sheets("RAW").Cells(i, 7).Value2)) * 60 _
    + Minute(TimeValue(Sheets("RAW").Cells(i, 7).Value2))