Object Required with CountIf()

Ernie

New member
Joined
Sep 26, 2016
Messages
3
Reaction score
0
Points
0
In the code fragment below the line: Cells(m,k)= Application.....)) raises a 424 Object Required error. I cant't resolve it. Under Tools I have installed Microsoft Excell 14.0 Object Library. I will appreciate finding out what I have missed.
Regards,
Ernie

Sub Test()
For J = 1 To 8 'for 8 numeric characters n serial number
For k = 14 To 21 'column
For m = 5 To 14 'row
Cells(m, k) = Application.WorksheetFunction.CountIf((Range(Cells(5, k - 10), Cells(maxk, k - 10))), Cells(m, 13))
Stop
Next
Next
Next
End Sub
 
Last edited by a moderator:
What is maxk? That's the only thing that I can see that looks suspicious.

Although I don't understand why you are Stoping the code after only one loop.
 
Thanks for your reply and questions. Here maxk is a contant defined earlier in the code of which I only included a fragment. The whole code is supposed to take a 8 x maxk matrrix and examine each column for the number of occurences of 0,1,2,3,4,5,6,7,8,9 using the CountIf() function. Then the result is written by Cells(m,k) to a 8 x 8 matrix.

The Stop command is present only as a debugging tool. I should have deleted it befor I sent the inquiry. The problem is that the expression Cells(m,k) = ... will not compile, but produces the 424 error. Appologies for not being more explicit.
Regards,
Ernie
 
Last edited by a moderator:
Please provide information if you ask a question.

No sample file, no suggestions.
 
As long as maxK is greater than 0, try
Code:
Application.WorksheetFunction.CountIf(Range(Cells(5, k - 10), Cells(maxk, k - 10)), Cells(m, 13).Value)
 
@ Ernie; Please do not quote entire posts unnecessarily. They clutter the forum

Also remember to wrap code with code tags Click Go advanced - select the code and click the #button. Thank you
 
I solved the problem. Replace
Cells(m,k) = Application. .... Cells(m, 13)
with
Set r =Range(Cells(5, k - 10), Cells(maxk, k - 10))
Cells(m, k) = Application.WorksheetFunction.CountIf(r, Cells(m, 13))
The moral is keep expressions simple.
 
I solved the problem. Replace
Cells(m,k) = Application. .... Cells(m, 13)
with
Set r =Range(Cells(5, k - 10), Cells(maxk, k - 10))
Cells(m, k) = Application.WorksheetFunction.CountIf(r, Cells(m, 13))
The moral is keep expressions simple.


Code tags please !
 
Back
Top