PDA

View Full Version : Using Countif in VBA



udigold1
08-28-2008, 12:53 PM
I have this problem:

I have 2 ranges with values, and I want to use countif to see of there's a same value in each of these ranges.

I wrote a code like this:

Sub countme()
Rng = Range("rngoriginal")
Range("criteria").Select
For Each cell In Selection
If Application.WorksheetFunction.CountIf(Rng, cell) > 0 Then
cell.EntireRow.Font.Bold = True
End If
Next cell
End Sub

but everytime I get to If line I get an error.
What am I doing wrong?

Thanks
Udi

Mavyak
08-28-2008, 01:34 PM
I think you're missing the Set keyword on this line:
Set Rng = Range("rngoriginal")

Aussiebear
08-28-2008, 02:19 PM
Hi Udi, Try using option explicit at the top of your code then debug. It'll pick up possibly some errors that you can fix