试试这个行否? Sub 统计焊缝数量() Dim arr() As String Dim findA As String Dim arr1 Dim sumB As Long findA = Selection.Cells(1).Range.Text findA = Mid(findA, 1, Len(findA) - 2) arr() = Split(findA, ",") For Each arr1 In arr sumB = sumB + sumA(arr1) Next MsgBox sumB End Sub Function sumA(findA) As Long Dim findB As String, findC As String Dim arr() As String If InStr(1, findA, "-") > 0 Then '前一段字符 findB = Mid(findA, 1, InStr(1, findA, "-") - 1) findB = Mid(findB, 1, InStr(1, findB, "A") - 1) '后一段字符 findC = Mid(findA, InStr(1, findA, "-") + 1, Len(findA) - InStr(1, findA, "-")) findC = Mid(findC, 1, InStr(1, findC, "A") - 1) sumA = CInt(findC) - CInt(findB) + 1 Else arr = Split(findA, "A") sumA = UBound(arr) End If End Function
[此贴子已经被作者于2007-1-2 8:25:24编辑过] |