Need VBA, instead using formula

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,422
Office Version
  1. 2010
Hello,</SPAN>

I got data in column D, is currently filled with 6500 rows, in the column F I do got unique list within 62000 rows, in the G4 entered formula =COUNTIF($D$4:$D$10000,F4) when i copy down to end 62000 rows it takes long tine to count and after i need to convert them in values it take back to much time</SPAN></SPAN>

My request is it, do this task have any VBA solution </SPAN></SPAN>


Book1
DEFG
1
2
3DATAUNIQUE LISTCOUNT
41|0 = 0|1 = 1|1 = 1|0 = 0|1 = 1|0 = 0|10|0 = 0|0 = 0|0 = 0|1 = 0|2 = 0|2 = 0|20
51|0 = 0|2 = 0|1 = 2|0 = 0|2 = 2|0 = 0|00|0 = 0|0 = 0|0 = 0|1 = 0|2 = 0|2 = 1|10
61|0 = 0|0 = 2|0 = 0|2 = 2|0 = 0|0 = 2|00|1 = 0|0 = 1|0 = 0|0 = 1|1 = 1|0 = 2|01
71|0 = 0|1 = 0|1 = 1|0 = 1|0 = 0|1 = 0|10|0 = 0|0 = 0|0 = 0|1 = 0|2 = 1|1 = 0|20
81|0 = 1|0 = 1|0 = 1|0 = 0|0 = 1|0 = 1|00|0 = 0|0 = 0|0 = 0|1 = 0|2 = 1|1 = 1|10
92|0 = 1|0 = 0|0 = 1|0 = 1|0 = 0|1 = 1|10|0 = 0|0 = 0|0 = 0|1 = 0|2 = 1|1 = 2|00
101|1 = 0|0 = 0|1 = 2|0 = 1|0 = 0|0 = 0|10|0 = 0|0 = 0|0 = 0|1 = 0|2 = 2|0 = 0|20
111|0 = 2|0 = 0|0 = 0|0 = 0|0 = 1|0 = 0|00|1 = 0|0 = 0|2 = 0|2 = 0|0 = 0|0 = 1|11
121|0 = 1|0 = 0|1 = 0|1 = 0|0 = 1|1 = 1|10|0 = 0|0 = 0|0 = 0|1 = 0|2 = 2|0 = 2|00
131|1 = 1|0 = 1|0 = 0|0 = 0|0 = 1|0 = 1|00|0 = 0|0 = 0|0 = 0|1 = 1|1 = 0|2 = 0|20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 0|0 = 1|00|0 = 0|0 = 0|0 = 0|2 = 1|0 = 0|2 = 1|10
541|0 = 0|0 = 1|0 = 0|1 = 0|0 = 1|1 = 0|00|0 = 0|0 = 0|0 = 0|2 = 1|0 = 0|2 = 2|00
550|0 = 2|0 = 1|0 = 0|0 = 2|0 = 1|1 = 0|00|0 = 0|0 = 0|0 = 0|2 = 1|0 = 1|1 = 0|20
560|1 = 0|1 = 0|0 = 1|1 = 1|0 = 2|0 = 1|00|0 = 0|0 = 0|0 = 0|2 = 1|0 = 1|1 = 1|10
570|0 = 1|0 = 0|1 = 0|0 = 0|0 = 1|0 = 1|00|0 = 0|0 = 0|0 = 0|2 = 1|0 = 1|1 = 2|00
580|1 = 0|1 = 1|0 = 0|0 = 0|0 = 1|0 = 1|00|0 = 0|0 = 0|0 = 0|2 = 1|0 = 2|0 = 0|20
590|0 = 0|0 = 0|1 = 1|0 = 0|2 = 1|0 = 1|00|0 = 0|0 = 0|0 = 0|2 = 1|0 = 2|0 = 1|10
600|1 = 1|0 = 0|0 = 1|0 = 0|0 = 2|0 = 1|10|0 = 0|0 = 0|0 = 0|2 = 1|0 = 2|0 = 2|00
610|0 = 0|0 = 1|0 = 1|0 = 0|0 = 0|1 = 0|10|0 = 0|0 = 0|0 = 0|2 = 1|1 = 0|1 = 0|20
620|0 = 0|0 = 0|0 = 0|1 = 0|1 = 0|0 = 1|00|0 = 0|0 = 0|0 = 0|2 = 1|1 = 0|1 = 1|10
630|1 = 0|0 = 0|2 = 0|2 = 0|0 = 0|0 = 1|10|0 = 0|0 = 0|0 = 0|2 = 1|1 = 0|1 = 2|00
Sheet1
Cell Formulas
RangeFormula
G4=COUNTIF($D$4:$D$10000,F4)


Thank you all</SPAN></SPAN>
Excel 2000</SPAN></SPAN>
Regards,</SPAN></SPAN>
Moti</SPAN></SPAN>
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
How about
Code:
Sub MyCountif()
   With Range("G4", Range("F" & Rows.Count).End(xlUp).Offset(, 1))
      .Value = Evaluate("if({1},countif($D$4:$D$10000," & .Offset(, -1).Address & "))")
   End With
End Sub
 
Upvote 0
Not sure if this is faster than the 'Evaluate' approach, but here's is my version.

Code:
Sub test()
Dim Dict As Object: Set Dict = CreateObject("Scripting.Dictionary")
Dim R As Range: Set R = Range("F4:F" & Range("F" & Rows.Count).End(xlUp).Row)
Dim AR1() As Variant: AR1 = Range("D4:D" & Range("D" & Rows.Count).End(xlUp).Row).Value
Dim AR2() As Variant: AR2 = R.Value


With Dict
    For i = 1 To UBound(AR2)
        .Add AR2(i, 1), 0
    Next i
    
    For j = 1 To UBound(AR1)
        If .exists(AR1(j, 1)) Then
            .Item(AR1(j, 1)) = .Item(AR1(j, 1)) + 1
        End If
    Next j
    
    R.Offset(, 1) = Application.Transpose(Array(.items))
End With


End Sub
 
Upvote 0
How about
Code:
Sub MyCountif()
   With Range("G4", Range("F" & Rows.Count).End(xlUp).Offset(, 1))
      .Value = Evaluate("if({1},countif($D$4:$D$10000," & .Offset(, -1).Address & "))")
   End With
End Sub
Fluff, thank you it worked perfect and took time 18,56 sec to finish, it is really very faster than the formula I were using</SPAN></SPAN>

Thank you for your help</SPAN></SPAN>

Kind Regards,</SPAN></SPAN>
Moti</SPAN></SPAN>
 
Upvote 0
Not sure if this is faster than the 'Evaluate' approach, but here's is my version.
lrobbo314, thank you for the code, please could you check it stop at the line below. And I am sure it is my excel version 2000 not the code.</SPAN></SPAN>
Code:
R.Offset(, 1) = Application.Transpose(Array(.items))

Kind Regards,</SPAN></SPAN>
Moti</SPAN></SPAN>
 
Upvote 0
What error is it giving you? Excel 2000 is pretty old. I tested the code and it works on this end. I don't know what about Excel 2000 would make it error out. Which is a bummer too because on my test data it was about 8x faster.
 
Upvote 0
I'm not sure you can transpose will work with 62000 values in xl2000
Try this modified version instead
Code:
Sub test()
Dim Dict As Object: Set Dict = CreateObject("Scripting.Dictionary")
Dim R As Range: Set R = Range("F4:G" & Range("F" & Rows.Count).End(xlUp).Row)
Dim AR1() As Variant: AR1 = Range("D4:D" & Range("D" & Rows.Count).End(xlUp).Row).Value
Dim AR2() As Variant: AR2 = R.Value


With Dict
    For i = 1 To UBound(AR2)
        .Add AR2(i, 1), i
        AR2(i, 2) = 0
    Next i
    
    For j = 1 To UBound(AR1)
        If .exists(AR1(j, 1)) Then
            AR2(.Item(AR1(j, 1)), 2) = AR2(.Item(AR1(j, 1)), 2) + 1
        End If
    Next j
    
    R.Offset(, 1).Resize(, 1) = Application.Index(AR2, 0, 2)
End With


End Sub
 
Upvote 0
Just tested the original code from lrobbo314 in Xl2003 & it works for me.
 
Upvote 0
Oh yeah, you're right. I always forget about that limitation, especially since my test data didn't have that many rows.

Good call Fluff!
 
Upvote 0
What error is it giving you? Excel 2000 is pretty old. I tested the code and it works on this end. I don't know what about Excel 2000 would make it error out. Which is a bummer too because on my test data it was about 8x faster.
lrobbo314, it is giving an error 13
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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