在 Excel 中计算字符串中的项目数

发布于 2024-11-08 19:24:05 字数 279 浏览 3 评论 0原文

我有一个下面提到的字符串,我需要在 2 个单独的列中返回结果

第 1 列:计算所有用分号分隔的位置。对于下面的示例,总共有 15 个名称,它们是用分号连接的。

第 2 列:在此之后,我需要计算有多少个名称以 A、B 和 B 开头。 C 还有多少没有。

A1604A;A3703E;A3703H;C2203H;F1001B;F1001C;F1001D;F1001E;F1001F;F1001G;F1001H;F1001J;F1001K;F1001L;F1001M

I have a string mentioned below and I need to return the results in 2 separate columns

Column 1: Count all the locations separating by Semicolon. for the below example, there are total of 15 names which are joined with semicolon

Column 2: After this I need to count how many names START with A, B & C and how many do not.

A1604A;A3703E;A3703H;C2203H;F1001B;F1001C;F1001D;F1001E;F1001F;F1001G;F1001H;F1001J;F1001K;F1001L;F1001M

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦回梦里 2024-11-15 19:24:05

迭代分割数组,增加 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)

Iterate the split array incrementing a counter array for A,B,C,Other;

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文