我正在尝试使用VBA在满足特定条件时对多个工作表上的列运行快速计算。
我需要在几个工作表的列范围内获取标记单元格的计数,其中工作表的名称以“BC”开头,并将结果返回到另一个工作表上的单元格。
有人可以帮忙吗?
''Generating worksheets from list of values
Sub CreateTemplates()
Set Template = Sheets("Test New Format")
For Each cell in Range("lstbc")
If cell <> "" Then
Template.Copy After:=Sheets(4)
ActiveSheet.Name = "BC" & cell.Value
cell.Offset(0,1).Value = "BC" & cell
End If
Next
End Sub
''Loop through sheets that begin with BC & calculate count
Sub LoopSheets()
Dim wb As Workbook
Dim ws As Worksheet
Dim myTotal as Double
Dim ProcessNum as Integer
ProcessNum = 0
For Each wb in Workbooks
For Each ws in Worksheets
Debug.Print ws.Name
If InStr(1, Left(ws.Name,2), "BC", vbTextCompare) > 0 Then
myTotal = myTotal+1
ProcessNum = ProcessNum + Application.WorksheetFunction.CountA(Range("E9:E116"))
End If
Next ws
Next wb
Sheets("console").Range("c18").Value = ProcessNum
End Sub
我生成了3个工作表,其名称中包含“BC”。来自myTotal的计数给了我3(看起来不错),但是当我尝试从每个工作表的列范围中获取计数时,我根本得不到正确的结果。