• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Count dynamic range

Abhijeet

Active Member
Hi
I have data in excel i want auto update count the name column data.I have mention in attach file expected data.please tell me how to do this
 

Attachments

  • Count.xlsx
    9.7 KB · Views: 8
I want count of in Name column mention but range is dynamic update automatic when in put Name any in column then that name & count update in Table in particular column.
 
Hi Try below code:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim lr As Long, lr1 As Long
lr = Range("A1048576").End(xlUp).Row
Application.ScreenUpdating = False
lr1 = Range("D1048576").End(xlUp).Row

If Not Intersect(Target, Range("A:A")) Is Nothing Then
    Range("D2:D" & lr1).Clear
    Range("A2:A" & lr).Copy Range("C2")
    lr1 = Range("C1048576").End(xlUp).Row
    Range("$C$2:$C$" & lr1).RemoveDuplicates Columns:=1, Header:=xlNo
    lr1 = Range("C1048576").End(xlUp).Row
    For i = 2 To lr1
        Range("D" & i).Value = Application.WorksheetFunction.CountIf(Range("A2:A" & lr), Range("C" & i))
    Next i
End If

Application.ScreenUpdating = True

   
End Sub

Regards,
 
Abhijet

I added a small piece of code to Somendra's code which will sort the output by Name, The Code also has instructions on how to sort it by Count

See attached:
 

Attachments

  • Count_Hui.xlsm
    17.1 KB · Views: 2
Back
Top