Count how many times avalue appears

paulsolar

Well-known Member
Joined
Aug 21, 2013
Messages
691
Office Version
  1. 365
Hi All

I'm getting stuck on a friday afternoon, which is never a good time to get stuck.

I have a worksheet (Sheet1) with loads of info in it that I'm trying to produce a regular report from on Sheet2.

What I'm trying to do I can almost get to work.

I want to get all the info from Sheet1 column I and copy it to Sheet2 column A, then in column B of Sheet2 is list the unique values in Sheet2 column A, so far so good.

Where i'm getting stuck is trying to count how many times each entry in column B appears in Sheet2 column A and list it in Sheet2 column C next to the item.

I hope I've explained it correctly.

Any help is greatly appreciated

Cheers

Paul

Code:
Private Sub Ininstallers()
Dim ws As Worksheet, ws1 As Worksheet
Dim lastrow As Long


Set ws = Worksheets("Sheet1")
Set ws1 = Worksheets("Sheet2")




    lastrow = ws.Cells(Rows.Count, 9).End(xlUp).Row
    ws.Range("I2", "I" & lastrow).Copy
    ws1.Range("A1").PasteSpecial xlPasteValues
    ws1.Activate
    
GetUniques
    
End Sub




Sub GetUniques()
Dim d As Object, c As Variant, i As Long, lr As Long
Set d = CreateObject("Scripting.Dictionary")
lr = Cells(Rows.Count, 1).End(xlUp).Row
c = Range("A1:A" & lr)
For i = 1 To UBound(c, 1)
  d(c(i, 1)) = 1
Next i
Range("B1").Resize(d.Count) = Application.Transpose(d.keys)
End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
How about
Code:
Sub GetUniques()
Dim d As Object, c As Variant, i As Long, lr As Long
Set d = CreateObject("Scripting.Dictionary")
lr = Cells(Rows.Count, 1).End(xlUp).Row
c = Range("A1:A" & lr)
For i = 1 To UBound(c, 1)
   If Not d.exists(c(i, 1)) Then
      d.Add c(i, 1), 1
   Else
      d.Item(c(i, 1)) = d.Item(c(i, 1)) + 1
   End If
Next i
Range("B1").Resize(d.Count) = Application.Transpose(d.keys)
Range("C1").Resize(d.Count) = Application.Transpose(d.items)
End Sub
 
Upvote 0
Hi Fluff

Brilliant thanks, sorted it in one go.

This will make life easy on Monday for me

cheers

Paul
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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