+ Reply to Thread
Results 1 to 9 of 9

VB Code to find unique names

Hybrid View

rizmomin VB Code to find unique names 10-16-2016, 02:16 PM
GC Excel Re: VB Code to find unique... 10-16-2016, 02:32 PM
TMS Re: VB Code to find unique... 10-16-2016, 03:21 PM
rizmomin Re: VB Code to find unique... 10-16-2016, 03:33 PM
TMS Re: VB Code to find unique... 10-16-2016, 03:35 PM
TMS Re: VB Code to find unique... 10-16-2016, 03:42 PM
GC Excel Re: VB Code to find unique... 10-16-2016, 04:10 PM
rizmomin Re: VB Code to find unique... 10-16-2016, 05:11 PM
TMS Re: VB Code to find unique... 10-16-2016, 05:37 PM
  1. #1
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    VB Code to find unique names

    Hello:

    Please refer to attached file.
    I have names as shown in Column G Cell G3 down.
    I need VB Code to do the following.
    1st replace text "SUPNA" by ""
    2nd Find unique names from list and paste at cell M3.

    Let me know if you have any questions.
    Thanks.

    Riz
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,414

    Re: VB Code to find unique names

    Hello Riz,

    Here's suggestion :

    Sub UniqueNames()
       Dim str As String
       Dim ar, i As Integer
       
       ar = Range("G3:G" & Range("G" & Rows.Count).End(xlUp).Row).Value
       With CreateObject("Scripting.dictionary")
          For i = 1 To UBound(ar, 1)
             str = Replace(ar(i, 1), "SUPNA", "")
             If Not .exists(str) Then .Add str, str
          Next i
          Range("M3").Resize(.Count, 1) = Application.Transpose(.keys)
       End With
    End Sub
    GC Excel

    If this post helps, then click the star icon (*) in the bottom left-hand corner of my post to Add reputation.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,526

    Re: VB Code to find unique names

    I'd be inclined to use an Advanced Filter, something like:

    Sub sExtractUniqueNames()
    Dim lLR As Long
    Application.ScreenUpdating = False
    lLR = Range("G" & Rows.Count).End(xlUp).Row
    Columns("G:G").Replace What:=" SUPNA", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    Range("G2").FormulaR1C1 = "Name"
    Columns("M:M").EntireColumn.Clear
    Range("G2:G" & lLR).AdvancedFilter _
        Action:=xlFilterCopy, _
        CopyToRange:=Range("M2"), Unique:=True
    Columns("M:M").EntireColumn.AutoFit
    Range("G2").Value = ""
    Range("M2").Value = ""
    Application.ScreenUpdating = True
    End Sub
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to find unique names

    Hello GC_Excel and TMS:

    Both solution will work great for me.
    Now i need code to add the unique list cell M3 down to Sheet2 at Q3.
    Thanks a lot

    Riz

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,526

    Re: VB Code to find unique names

    Why don't you just put the list straight out to Sheet2?

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,526

    Re: VB Code to find unique names

    Sub sExtractUniqueNames()
    Dim lLR As Long
    Application.ScreenUpdating = False
    lLR = Range("G" & Rows.Count).End(xlUp).Row
    Columns("G:G").Replace What:=" SUPNA", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    Range("G2").FormulaR1C1 = "Name"
    Columns("M:M").EntireColumn.Clear
    Range("G2:G" & lLR).AdvancedFilter _
        Action:=xlFilterCopy, _
        CopyToRange:=Range("M2"), Unique:=True
    Columns("M:M").EntireColumn.AutoFit
    Range("G2").Value = ""
    Range("M2").Value = ""
    
    lLR = Range("M" & Rows.Count).End(xlUp).Row
    With Sheets("Sheet2")
        .Columns("Q:Q").EntireColumn.Clear
        Sheets("sheet1").Range("M3:M" & lLR).Copy .Range("Q3")
    End With
    Application.ScreenUpdating = True
    End Sub

  7. #7
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,414

    Re: VB Code to find unique names

    Like this ?

    Sub UniqueNames()
       Dim str As String
       Dim ar, i As Integer
       
       ar = Range("G3:G" & Range("G" & Rows.Count).End(xlUp).Row).Value
       With CreateObject("Scripting.dictionary")
          For i = 1 To UBound(ar, 1)
             str = Replace(ar(i, 1), "SUPNA", "")
             If Not .exists(str) Then .Add str, str
          Next i
          Range("M3").Resize(.Count, 1) = Application.Transpose(.keys)
          With Sheets("Sheet2")
               .Range("Q3").resize(10000,1).Clear    'Clear 10000 rows 
               .Range("Q3").Resize(.Count, 1) = Application.Transpose(.keys)
          End With
       End With
    End Sub

  8. #8
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to find unique names

    Hello TMS and GC"

    Works for me....Thanks a lot.

    Riz

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,526

    Re: VB Code to find unique names

    You're welcome. Thanks for the rep.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Code to find Unique Names
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-19-2016, 04:29 PM
  2. VB Code to find Unique Names
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 08-30-2015, 06:42 PM
  3. [SOLVED] Need vba code to make sum and average of row depends upon unique names in col A
    By breadwinner in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-02-2015, 02:54 AM
  4. vba find unique names in multiple columns
    By Konexcelmath in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-26-2014, 09:10 PM
  5. Find unique names in certain range.
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 07-22-2014, 04:00 PM
  6. Excel 2007 - Formula or VBA to find unique names and return values?
    By kjwaller in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-02-2013, 09:09 PM
  7. [SOLVED] Find unique names and count their status
    By webstmonkey in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-14-2013, 01:17 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1