How to use dictionary method instead the function Countif in VBA?

Gabrielle9

New Member
Joined
Jan 25, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi! I want to use vba dictionary method because i have over 200k rows which takes a lot of time to run. I found that using dictionary method would be faster than Worksheet countif function, but i could not find somethig to convert my formula to something that will return each appearence of the duplicate value

My excel formula:
=If(countif($N$2:$B$200122,N2)>1,"Duplicate value", " ")

=If(countif($N$2:$B$200122,N3)>1,"Duplicate value", " ")
..............
If(countif($N$2:$B$200122,N200122)>1,"Duplicate value", " ")

Vba code:

Lastrow= cells(rows.count,2).end(xlUp).row
For n=2 to lastrow
If application.countif(range("N2:N") & last row), Range ("N" & n)) > 1 then
Range("O" & n).Value = true
Else
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Range("O" & n).Value = false
End if
Next n
This is the my complete code. Is posible to use dictionary to have the same result as when i use countif function?
Thanks!
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,388
Members
448,957
Latest member
Hat4Life

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top