Extract unique names from within cells and paste in to a new

inarbeth

Well-known Member
Joined
Apr 8, 2002
Messages
913
I have a database with parties to various legal documents listed within a large range called Parties. The range is presently in cells F3:F750 but may be expanded. Typically a cell contains information such as: ZZ Top (1) Acme Engineering 1987 Limited (2) John Lee Hooker(3).
(I made those names up.)
What I want to do is to run a macro to extract all names of more than two characters length and paste them in a column on Sheet 4 but once only. Thus if "Hooker" or "1987" appears several times they will appear once only on Sheet 4.
 
I want individual names extracted. If you can extract
H J Cotton
H Lainson
H W Pemberton
including the initials that would be brilliant. I had expected to extract
Cotton
Lainson and
Pemberton

with their initials not being counted because of my minimum of three characters criterion. That might be safer to avoid getting a name plus a bracket or a full stop.
 
Upvote 0

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Try this:

Code:
Sub Test()
    Dim Rng As Range
    Dim c As Range
    Dim Party As String
    Dim x As Integer
    Dim Char As Variant
    Dim Parties As New Collection
    Dim Item As Variant
    Set Rng = Range("A2:A" & Range("A65536").End(xlUp).Row)
    For Each c In Rng
        Party = ""
        x = 1
        Do
            Char = Mid(c.Text, x, 1)
            If Char = "," Then
                If Len(Trim(Party)) > 0 Then
                    On Error Resume Next
                    Parties.Add Trim(Party), Trim(Party)
                    Party = ""
                    On Error GoTo 0
                End If
            ElseIf Char = "(" Then
                If Len(Trim(Party)) > 0 Then
                    On Error Resume Next
                    Parties.Add Trim(Party), Trim(Party)
                    Party = ""
                    On Error GoTo 0
                    x = x + 2
                End If
            Else
                Party = Party & Char
            End If
            x = x + 1
            If x > Len(c.Text) Then
                On Error Resume Next
                If Len(Trim(Party)) Then
                    Parties.Add Trim(Party), Trim(Party)
                End If
                On Error GoTo 0
                Exit Do
            End If
        Loop
    Next c
    Worksheets.Add
    x = 1
    For Each Item In Parties
        ActiveSheet.Cells(x, 1).Value = Item
        x = x + 1
    Next Item
End Sub

It puts them on a new sheet, but I'm sure you can live with that.
 
Upvote 0
Andrew
You are a star. That works brilliantly. I could never have attempted this manually.
Many thanks.
Ian :biggrin:
This message was edited by inarbeth on 2002-11-01 12:34
 
Upvote 0

Forum statistics

Threads
1,215,772
Messages
6,126,803
Members
449,337
Latest member
BBV123

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