[英]Excel split based on string
I am having below type of values in xls column A 我在xls列A中具有以下值的类型
Row 1 - 3min 17s 463ms
Row 2 - 19s 364ms
Row 3 - 165ms
Row 4 - 364ms
Row 5 - 4min 1s 463ms
Form my calculation I need to convert above values into ms (milli seconds), I have tried doing this (with my limited VBScripting knowledge) using split functions but I couldn't make it work :(. Can you please help. 从我的计算中,我需要将上述值转换为ms(毫秒),我尝试使用拆分函数(使用我有限的VBScripting知识)执行此操作,但我无法使其工作:(。请帮忙。
Thank You, V2ri. 谢谢V2ri。
How about: 怎么样:
Sub millisec()
Dim A As Range, r As Range, s As String
Dim N As Long, milli As Long
N = Cells(Rows.Count, "A").End(xlUp).Row
Set A = Range("A1:A" & N)
For Each r In A
v = r.Text
ary = Split(v, " ")
milli = 0
For Each ar In ary
If Right(ar, 2) = "ms" Then
milli = milli + CLng(Replace(ar, "ms", ""))
GoTo qwerty
End If
If Right(ar, 1) = "s" Then
milli = milli + 1000& * CLng(Replace(ar, "s", ""))
GoTo qwerty
End If
milli = milli + 60& * 1000& * CLng(Replace(ar, "min", ""))
qwerty:
Next ar
r.Value = milli
Next r
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.