Manasa J
Manasa J

Reputation: 37

Count if across multiple worksheets excel vba

I am getting object defined error while running the below code.Please help me debug the code.

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

Upvotes: 0

Views: 7630

Answers (1)

Joe Laviano
Joe Laviano

Reputation: 1048

You need quotes around your columns, otherwise F and G are variables.

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

Upvotes: 1

Related Questions