Countif Formula using For Each ....Next loop

vranjit138

Board Regular
Joined
Dec 18, 2006
Messages
141
Hi Friends

i have invoice numbers many of them mostly repeating in Column A
in Column how can i show which invoice repeats how many times and
the time it repeats using macro..
Iam pretty comfortable with For Each ... Next loop but iam unable to
use it here. What i trying is get the countif fuction in this loop

Can anyone help me with this loop

Regards
ranjit
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

ravishankar

Well-known Member
Joined
Feb 23, 2006
Messages
3,566
Hi
Paste the following codes in the macro window ( alt F11)

Code:
Sub Macro1()
'find unique invoice numbers
  x = Cells(Rows.Count, 1).End(xlUp).Row
  a = "A1:A" & x
    Range(a).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("B1" _
        ), Unique:=True
'count their occurance
        y = Cells(Rows.Count, 2).End(xlUp).Row
        For b = 2 To y
        Cells(b, 3) = "=CountIf(" & a & ", B" & b & ")"
        Next b
End Sub
run the macro. It will find unique invoice numbers in col B and their counts in col C
Ravi
 

Forum statistics

Threads
1,181,649
Messages
5,931,216
Members
436,784
Latest member
amuljono

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
Top