Hi All,
I am trying to create a VBA script to look through an automatic generated report on one of the tabs called "All". What I need it to do is look through Column "A" and find the unique Entries and how many times these unique entries appear. Then put the results in a new tab called "Summary".
[table="width: 500, class: grid, align: center"]
[tr]
[td]GpBr[/td]
[td]#[/td]
[/tr]
[tr]
[td]U111[/td]
[td]1234[/td]
[/tr]
[tr]
[td]U111[/td]
[td]1235[/td]
[/tr]
[tr]
[td]U112[/td]
[td]1236[/td]
[/tr]
[tr]
[td]U112[/td]
[td]1237[/td]
[/tr]
[tr]
[td]U113[/td]
[td]1238[/td]
[/tr]
[tr]
[td]U114[/td]
[td]1239[/td]
[/tr]
[/table]
So once I have run the script it will create a new summary tab with the following.
[table="width: 500, class: grid, align: center"]
[tr]
[td]Unique Entries[/td]
[td]Occurences[/td]
[/tr]
[tr]
[td]U111[/td]
[td]2[/td]
[/tr]
[tr]
[td]U112[/td]
[td]2[/td]
[/tr]
[tr]
[td]U113[/td]
[td]1[/td]
[/tr]
[tr]
[td]U114[/td]
[td]1[/td]
[/tr]
[/table]
I did manage to find some code but I cant get it to work how I need to by creating a new "Summary" tab etc.
Thank you for your help
GS!
I am trying to create a VBA script to look through an automatic generated report on one of the tabs called "All". What I need it to do is look through Column "A" and find the unique Entries and how many times these unique entries appear. Then put the results in a new tab called "Summary".
[table="width: 500, class: grid, align: center"]
[tr]
[td]GpBr[/td]
[td]#[/td]
[/tr]
[tr]
[td]U111[/td]
[td]1234[/td]
[/tr]
[tr]
[td]U111[/td]
[td]1235[/td]
[/tr]
[tr]
[td]U112[/td]
[td]1236[/td]
[/tr]
[tr]
[td]U112[/td]
[td]1237[/td]
[/tr]
[tr]
[td]U113[/td]
[td]1238[/td]
[/tr]
[tr]
[td]U114[/td]
[td]1239[/td]
[/tr]
[/table]
So once I have run the script it will create a new summary tab with the following.
[table="width: 500, class: grid, align: center"]
[tr]
[td]Unique Entries[/td]
[td]Occurences[/td]
[/tr]
[tr]
[td]U111[/td]
[td]2[/td]
[/tr]
[tr]
[td]U112[/td]
[td]2[/td]
[/tr]
[tr]
[td]U113[/td]
[td]1[/td]
[/tr]
[tr]
[td]U114[/td]
[td]1[/td]
[/tr]
[/table]
I did manage to find some code but I cant get it to work how I need to by creating a new "Summary" tab etc.
Code:
Sub Special_Countif()
Dim i, LastRowA, LastRowB
LastRowA = Range("A" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
Application.EnableEvents = False
Columns("B:C").ClearContents
For i = 1 To LastRowA
If Application.CountIf(Range("B:B"), Cells(i, "A")) = 0 Then
Cells(i, "B").Offset(1, 0).Value = Cells(i, "A").Value
End If
Next
Columns("B:B").Select
Selection.Sort Key1:=Range("B1"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
LastRowB = Range("B" & Rows.Count).End(xlUp).Row
For i = 2 To LastRowB
Cells(i, "C").Value = Application.CountIf(Range("A:A"), Cells(i, "B"))
Next i
Range("B1").Value = "Unique Entries"
Range("C1").Value = "Occurrences"
Range("B1:C1").HorizontalAlignment = xlCenter
Range("B1").Select
Columns("B:C").AutoFit
Application.EnableEvents = True
End Sub
Thank you for your help
GS!