How to exclude requested values?

Ofirabo

New Member
Joined
Mar 15, 2011
Messages
6
Hello,

I have many "text values" in one column, i want to exclude the values that appears just once and display them in a differnet column.
what function should i use and how?
for example:
apple
apple
apple
orange
tomato
tomato

Thanks
Ofira
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
20,890
Office Version
  1. 365
Platform
  1. Windows
Assuming that Column A contains the text values, the following macro will list in Column C values that occur more than once...

Code:
[font=Verdana][color=darkblue]Option[/color] [color=darkblue]Explicit[/color]

[color=darkblue]Sub[/color] test()

    [color=darkblue]Dim[/color] LastRow [color=darkblue]As[/color] [color=darkblue]Long[/color]
    [color=darkblue]Dim[/color] NextRow [color=darkblue]As[/color] [color=darkblue]Long[/color]
    [color=darkblue]Dim[/color] i [color=darkblue]As[/color] [color=darkblue]Long[/color]
    
    Application.ScreenUpdating = [color=darkblue]False[/color]

    LastRow = Cells(Rows.Count, "A").End(xlUp).Row
    
    NextRow = 1
    [color=darkblue]For[/color] i = 1 [color=darkblue]To[/color] LastRow
        [color=darkblue]If[/color] WorksheetFunction.CountIf(Range(Cells(1, "A"), Cells(LastRow, "A")), Cells(i, "A").Value) > 1 [color=darkblue]Then[/color]
            Cells(NextRow, "C").Value = Cells(i, "A").Value
            NextRow = [color=darkblue]Next[/color]Row + 1
        [color=darkblue]End[/color] [color=darkblue]If[/color]
    Next i
    
    Application.ScreenUpdating = [color=darkblue]True[/color]
    
    MsgBox "Completed...", vbInformation
    
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
[/font]

If you in fact want a list of text values than occur only once, try replacing...

Code:
If WorksheetFunction.CountIf(Range(Cells(1, "A"), Cells(LastRow, "A")), Cells(i, "A").Value) > 1 Then

with

Code:
If WorksheetFunction.CountIf(Range(Cells(1, "A"), Cells(LastRow, "A")), Cells(i, "A").Value) = 1 Then
 
Upvote 0

Forum statistics

Threads
1,190,677
Messages
5,982,209
Members
439,768
Latest member
loukrs

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
Top