VBA Countif taking to Long think maybe Dictionary?

anthonyexcel

Active Member
Joined
Jun 10, 2011
Messages
258
Office Version
  1. 365
Platform
  1. Windows
Good morning,

I have 300,000 rows of data in Column A. I am using a Macro that has countif in it and it takes forever to run. I am looking to have a running count greater than 1. Can anyone offer me a different solution? Thanks in advance!

Code:
Sub CountingMoreThanOne()
Dim LR As Integer
LR = Range("A" & Rows.Count).End(xlUp).Row
    With Range("B2:B" & LR)
        .Formula = "=IF(COUNTIF($A$2:A2,A2)>1,"""",IF(COUNTIF($A$2:$A$26000,A2)>1,COUNTIF($A$2:$A$26000,A2),""""))"
        .Value = .Value
    End With
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
How about
Code:
Sub CountingMoreThanOne()
   Dim Cl As Range
   Dim Itm As Variant
   Dim tmp As Variant
   
   With CreateObject("scripting.dictionary")
      For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
         If Not .exists(Cl.Value) Then
            .Add Cl.Value, Array(Cl, 1)
         Else
            tmp = .Item(Cl.Value)
            tmp(1) = tmp(1) + 1
            .Item(Cl.Value) = tmp
         End If
      Next Cl
      For Each Itm In .items
         If Itm(1) > 1 Then Itm(0).Offset(, 1).Value = Itm(1)
      Next Itm
    End With
End Sub
 
Upvote 0
Fluff! Amazing! That is exactly what I am after!! I appreciate all of your help!! Thanks again!
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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