首页 文章

查找并计算工作表中的出现次数

提问于
浏览
2

我需要找出使用VBA在一张纸上出现一系列数字的次数 . 例如:

201-1 -55-8799

301-5-55-8799

202-1-55-8799

201-1 -55-8799

999-5-55-8799

001-2-55-8799

我想知道201-1在这张表中出现了多少次 . 当您在Excel中执行FindAll时,它会在底部告诉您找到了多少个单元格 .

我已经尝试过CountIf,但只有在单元格恰好包含201-1时才有效 .

上述搜索的答案应该是201-1发现的2个实例 .

然后我需要在不同的表格中写出出现次数 .

谢谢

3 回答

  • 2

    使用 COUNTIF 公式

    =COUNTIF(A2:A12,"201-1*")

    enter image description here

    enter image description here

    enter image description here

  • 0

    您可以使用VBA执行此操作

    Dim tab_input as Variant
    
    tab_input = ~your range~
    specific_counter = 0
    
    For i = 1 to Ubound(tab_input)
     If Left(tab_input(i,1),5) = "201-1" Then
       specific_counter = specific_counter + 1
    
      End If
    Next
    
    msgbox specific_counter
    

    这将计算从201-1开始留下文本的单元格数量,并在框中显示金额 .

  • 0

    我建议以编程方式使用Excel自己的查找功能 . 像这样的东西:

    http://www.ozgrid.com/VBA/find-method.htm

相关问题