Countif Formula using For Each ....Next loop

vranjit138

Board Regular
Joined
Dec 18, 2006
Messages
146
Office Version
  1. 365
Platform
  1. Windows
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

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
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
 
Upvote 0

Forum statistics

Threads
1,214,954
Messages
6,122,461
Members
449,085
Latest member
ExcelError

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