Hi,
I am struggling to come up with a solution to my problem. I have a list of, for example, fruit and the names of these fruit appear more than once in a list. I do not know the names of the fruit prior to executing a piece of code so cannot lookup from anywhere. I have produced the following code which works, except it includes the name of the fruit in cell C2 and it's corresponding count twice. Code:
Sub CalcTotalFruit()
Worksheets("Fruit").Activate
With ActiveSheet
.Range("C2", Range("C2").End(xlDown)).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range( _
"G2"), Unique:=True
.Names("Extract").Delete
Dim lrC As Long, lrG As Long
lrC = Cells(Rows.Count, "C").End(xlUp).Row
lrG = Cells(Rows.Count, "G").End(xlUp).Row
Range("H2:H" & lrG).Formula = "=COUNTIF($C$2:$C$" & lrC & ",$G2)"
End With
End Sub
I have also attached sample data.
If anyone can help me understand where I am going wrong I would be grateful. Also suggestions on how to improve the code in general is welcome!
Thanks
Book1.xls
Bookmarks