EXCEL中,如何将时分秒不规则的字符串,转换成分钟数值,
网上有很多时分秒转分钟的例子,但都是基于规则的**时**分**秒来转换的,
下面是对不规则时分秒字符串格式的数据,通过Excel中宏编程,自定义getMinByTime()函数实现,具体如下
不规则的时分秒数据如下:
宏编程的代码如下:
Function getMinByTime(s)
Dim num
Dim tmp
num = 0
If (InStr(1, s, "时") <> 0) Then
tmp = Split(s, "时")
num = val(tmp(0)) * 60
If (UBound(tmp) - LBound(tmp) + 1 >= 2) Then
s = LTrim(RTrim(tmp(1)))
Else
s = ""
End If
End If
If (InStr(1, s, "分") <> 0) Then
tmp = Split(s, "分")
num = num + val(tmp(0))
If (UBound(tmp) - LBound(tmp) + 1 >= 2) Then
s = LTrim(RTrim(tmp(1)))
Else
s = ""
End If
End If
If (InStr(1, s, "秒") <> 0) Then
tmp = Split(s, "秒")
If (val(tmp(0)) > 30) Then
num = num + 1
End If
End If
getMinByTime = num
End Function
转换后的效果为: