You do you mean by "based off of what the user selects in a combobox"? Do
you mean find multiple instances of a value in a combobox?
If you combobox is on Sheet1 and named ComboBox1, you can call the following
code from the combobox's Change event:
Sub SelectDups()
Dim RR As Range
Dim R As Range
Dim V As Variant
Dim Dups As Range
With Worksheets("Sheet1")
Set RR = .Range(.Range("A1"), .Cells(.Rows.Count, "A").End(xlUp))
End With
V = Sheet1.ComboBox1.Value
If V = vbNullString Then
Exit Sub
End If
For Each R In RR
If StrComp(V, R.Text, vbTextCompare) = 0 Then
If Dups Is Nothing Then
Set Dups = R
Else
Set Dups = Application.Union(Dups, R)
End If
End If
Next R
If Not Dups Is Nothing Then
Dups.Select
End If
End Sub
--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)
"Mekinnik" wrote in message
...
I found this code that Tom Ogilvy created for searching for duplicates and
I
was wondering if it is possible to modify the code the search for
duplicates
based off of what the user selects in a combobox? I know that this code
not
only searches but also copies, I was just going to leave out the copy
part?
Sub FindDuplicates()
Dim colNum as String
Dim rng as range, cell as Range
Dim rng1 as Range
colNum = "A"
With Activesheet
set rng = .Range(.Cells(1,colNum), _
.Cells(rows.count,colNum).End(xlup))
End With
for each cell in rng
if application.Countif(rng,cell) 1 then
if rng1 is nothing then
set rng1 = cell
else
set rng1 = Union(rng1,cell)
end if
end if
Next
If not rng1 is nothing then
rng1.entireRow.Copy Sheets(2).Range("A1")
End if
End Sub