count unique values ​​in a column

sassa198614

New Member
Joined
Jun 6, 2018
Messages
1
Good morning,
I'm an Italian guy who uses excel for small jobs in the office, the problem that I can not solve is this:
The file consists of a series of data in a column and I need the macro to do a count of the number of times a word appears in the column, then the macro in two other columns inserts me:

- in the first column the word found,

- in the column next to the number of times the word is present in the main column "names", as indicated in sheet1.
My problem is where in the main column "names" there are empty boxes, I would like to eliminate the count of empty boxes that the macro indicates to me with ZERO and also insert all the full boxes of the column.



the code:

Sub foglio1contarevalori()
Sheets("Foglio1").Activate
Range("a1").Select

Set rngData = Sheets("Foglio1").Range("a1", Sheets("Foglio1").Range("a1").End(xlDown))


rngData.AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=Cells(1, 3), Unique:=True
Set rngUniqueData = Range("c1", Range("c1").End(xlDown))
With rngUniqueData
For lngRow = 2 To .Rows.Count
lngCount = Application.WorksheetFunction.CountIf(rngData, .Cells(lngRow, 1).Value)
.Cells(lngRow, 1).Offset(0, 1).Value = lngCount
Next
End With
End Sub






I thank you for your attention and I hope for some help
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
The range that is defined when you use End(xlDown) will only include cells prior to the first empty one. Therefore, try defining your range as follows...

Code:
With Sheets("Foglio1")
    Set rngData = .Range("a1", .Cells(.Rows.Count, "a").End(xlUp))
End With

Hope this helps!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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