Count same values in collumn

Flash0220

Board Regular
Joined
May 2, 2002
Messages
104
Hello,


I'm having the following little problem, and i'm hoping that someone at
this message board can help me solve it.

I have (in collumn A) a number of numerical values.
The collumn containing the values starts at cell A2 and ends at the row number
stored in the variable "EndRowDatabase".

A B
8043 1
8446 1
8501 2
8501 2
9289 1
9390 1
9465 2
9465 2

I also have a collumn (B) which lists how many times
the number (in collumn A) is in the database.

So if number 8501 appears 2 times in collumn A, the
number 2 has to appear in each cell next to the cell
containing the value 8501.

Is there an easy way to do this using VBA only ?
(I'm using the dutch version of Excel 2003.)

Best regards,


Flash0220
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Probeer deze code eens (Try this code)

Code:
Sub AantalWaarden()

Dim c As Variant
Dim d As Variant
Dim Teller As Long

  For Each c In Range("A2:" & EndRowDatabase)
    Teller = 0
    For Each d in Range("A2:" & EndRowDatabase)
      If c.Value = d.Value Then
        Teller = Teller + 1
      End If
    Next d
    c.OffSet(0,1).Value = Teller
  Next c

End Sub

Success
 
Upvote 0
I don't know about Dutch version, but would this suffice?
Code:
With Range("B2:B" & EndRowDatabase)
    .Formula = "=COUNTIF(A$2:A$" & EndRowDatabase & ",A2)"
    .Value = .Value
End With
 
Upvote 0
Dutch version would be :

Code:
With Range("B2:B" & EndRowDatabase)
    .Formula = "=AANTAL.ALS(A$2:A$" & EndRowDatabase & ";A2)"
    .Value = .Value
End With
 
Upvote 0
Dutch version would be :

Code:
With Range("B2:B" & EndRowDatabase)
    .Formula = "=AANTAL.ALS(A$2:A$" & EndRowDatabase & ";A2)"
    .Value = .Value
End With
Thanks. If there was 1,000 rows, that should be a lot simpler than looping 1,000 x 1,000 = 1,000,000 times. :)
 
Upvote 0
I agree with you Peter. Formulas in VBA is not my thing, but this is much faster than what I produced.
 
Upvote 0
Hello,


Thanks a lot for this code.
It works perfectly.
(And very fast.)
Thanks !


Best regards,
Flash0220
 
Upvote 0

Forum statistics

Threads
1,224,524
Messages
6,179,308
Members
452,904
Latest member
CodeMasterX

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