我有一个下面提到的字符串,我需要在两个单独的列中返回结果
第1列:计算以分号分隔的所有位置。对于下面的示例,总共有15个名称与分号
连接第2栏:在此之后,我需要计算从A,B和B开始的名称数量。 C和多少没有。
A1604A;A3703E;A3703H;C2203H;F1001B;F1001C;F1001D;F1001E;F1001F;F1001G;F1001H;F1001J;F1001K;F1001L;F1001M
答案 0 :(得分:3)
迭代分裂数组,为A,B,C,其他;
递增计数器数组Dim str As String: str = "A123;A456;B111;C222;C333;ZXX;Y66"
Dim items() As String
Dim i As Long
Dim pfx(3) As Long
Dim key As Long
items = Split(str, ";")
For i = 0 To UBound(items)
Select Case Left(items(i), 1)
Case "A", "B", "C"
key = Asc(Left(items(i), 1)) - 65 '//convert to 0,1,2 for counter index
Case Else
key = 3
End Select
pfx(key) = pfx(key) + 1
Next
Range("A1").Value = "total: " & UBound(items) + 1
Range("B1").Value = "A total: " & pfx(0)
Range("C1").Value = "B total: " & pfx(1)
Range("D1").Value = "C total: " & pfx(2)
Range("E1").Value = "Other total: " & pfx(3)