如果跨多个工作表优于vba,请计算

时间:2013-10-30 17:25:37

标签: excel-vba vba excel

运行以下代码时出现对象定义错误。请帮我调试代码。

For i = 5 To 11
Cells(i, G).Value = Application.WorksheetFunction.CountIf(Workbooks(1).Sheets(1).Range("H:H"), Cells(i, F).Value) + Application.WorksheetFunction.CountIf(Workbooks(1).Sheets(2).Range("H:H"), Cells(i, F).Value)
Next i

1 个答案:

答案 0 :(得分:1)

您的列周围需要引号,否则F和G是变量。

For i = 5 To 11
Cells(i, "G").Value = Application.WorksheetFunction.CountIf(Workbooks(1).Sheets(1).Range("H:H"), Cells(i, "F").Value) + Application.WorksheetFunction.CountIf(Workbooks(1).Sheets(2).Range("H:H"), Cells(i, "F").Value)
Next i