Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Count duplicate values in a selection

Dear All,

I want to count in a msgbox all duplicate values in selection through a
macro any ideas??
--
Regards,

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Count duplicate values in a selection

in the development environment, set s reference (Tools/References) to the
Microsoft Scripting Runtime DLL. We'll use the collection dictionary to count
the items

add this code

Option Explicit
Sub GetDuplicates()
Dim dic As Scripting.Dictionary
Dim cell As Range
' this is tehy results container
Set dic = New Scripting.Dictionary
' gather the results
For Each cell In Selection.Cells
If dic.Exists(cell.Value) Then
dic.Item(cell.Value) = dic.Item(cell.Value) + 1
Else
dic.Add cell.Value, 1
End If
Next
' output the results
Dim ws As Worksheet
Dim rw As Long
Set ws = Worksheets.Add
For rw = 1 To dic.Count
ws.Cells(rw, 1) = dic.Keys(rw - 1)
ws.Cells(rw, 2) = dic.Items(rw - 1)
Next
Set dic = Nothing
End Sub


"Abdul Shakeel" wrote:

Dear All,

I want to count in a msgbox all duplicate values in selection through a
macro any ideas??
--
Regards,

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I count once, multiple duplicate values? Rolf Excel Worksheet Functions 1 February 19th 09 04:18 AM
Find and Count Duplicate values mikeb Excel Programming 1 December 12th 08 01:49 PM
Count Duplicate Values Abdul Shakeel Excel Discussion (Misc queries) 2 February 29th 08 04:31 PM
How to count duplicate or repeat values Roshlin Excel Discussion (Misc queries) 12 January 28th 08 10:55 PM
Count duplicate values in worksheet Quek HS Excel Programming 2 May 18th 05 04:08 AM


All times are GMT +1. The time now is 02:31 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"