475CDY
08-26-2022, 11:59 AM
Hi,
I have a column of just under 62,000 rows where I am trying to get an accurate count for each value on each row. If I type =COUNTIF($J$2:$J$61948,J2) in cell K2 and copy it down, then it works correctly. However, I want to be able to run it using VBA, but it keeps blowing up on me. Here is the module that I am using:
Sub PrimaryCount()
Dim LastRow as long
LastRow = Cells(Rows.Count, 13).End(xlUp).Row
Range("K2:K" & LastRow).Value = "=COUNTIF($J$2:$J$& LastRow,J2)" <- 1004 error
End Sub
When I try to run the code I get a Run-time error ‘1004’: Application-defined or object-defined error. After I get the error, if I highlight the row I get a “<type mismatch>” on what appears to be the second "LastRow" underlined above. What do I need to fix to make this work using VBA – or – is there a better option?
Mark
I have a column of just under 62,000 rows where I am trying to get an accurate count for each value on each row. If I type =COUNTIF($J$2:$J$61948,J2) in cell K2 and copy it down, then it works correctly. However, I want to be able to run it using VBA, but it keeps blowing up on me. Here is the module that I am using:
Sub PrimaryCount()
Dim LastRow as long
LastRow = Cells(Rows.Count, 13).End(xlUp).Row
Range("K2:K" & LastRow).Value = "=COUNTIF($J$2:$J$& LastRow,J2)" <- 1004 error
End Sub
When I try to run the code I get a Run-time error ‘1004’: Application-defined or object-defined error. After I get the error, if I highlight the row I get a “<type mismatch>” on what appears to be the second "LastRow" underlined above. What do I need to fix to make this work using VBA – or – is there a better option?
Mark