首页 文章

在excel中创建宏

提问于
浏览
-4

请帮我创建一个宏,该宏在工作簿中搜索特定列的多个工作表,并显示该列中的值计数,并显示在包含工作表名称和计数的新工作表中 .

我有3张名为A,B和C的表 . 我已经尝试了以下代码,但它不是根据列 Headers 名称计算的 .

我有专栏

公司公司公司ABC ABC ABC DEF GHI
JKL

结果应该是这样的

表单名称计数A 1 B 3 C 2

Sub Click()Dim sh As Worksheet,ws As Worksheet,LstRw As Long,x,s As String Dim rng1 As Range

Set ws = Sheets.Add
ws.Name = "Report"
s = "A"
For Each sh In Sheets
    If sh.Name <> ws.Name Then
        With sh

              x = Application.WorksheetFunction.CountA(.Range("A:A"))
            With ws
                LstRw = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
                .Cells(LstRw, 1) = sh.Name
                .Cells(LstRw, 2) = x

            End With
        End With
    End If
Next sh

结束子

谢谢

1 回答

相关问题