+ Reply to Thread
Results 1 to 6 of 6

List Unique Values from two worksheet in to Results TAB

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-01-2020
    Location
    CHENNAI
    MS-Off Ver
    EXCEL 2010
    Posts
    105

    List Unique Values from two worksheet in to Results TAB

    Hi

    I want to list unique values from two worksheet in to new worksheet
    by selecting the range from sheet 1 and sheet 2. Columns and worksheets are not fixed one, hence wants to select through Range.

    Seeking help of VBA code for this.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,908

    Re: List Unique Values from two worksheet in to Results TAB

    Please post a better example with data showing what is required as it far from clear to me based on your posted file.
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  3. #3
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2503
    Posts
    1,459

    Re: List Unique Values from two worksheet in to Results TAB

    One method using arrays and a collection:
    Sub NoDups()
        Dim var1 As Variant, var2 As Variant, var3 As Variant
        Dim col As New Collection, fVar() As String
        
        var1 = Application.InputBox(prompt:="Select range 1", Type:=8).Value
        var2 = Application.InputBox(prompt:="Select range 2", Type:=8).Value
        var3 = Split(Join(Application.Transpose(var1), ",") & "," & Join(Application.Transpose(var2), ","), ",")
        Erase var1: Erase var2
        On Error Resume Next
        For x = 0 To UBound(var3)
            col.Add var3(x), CStr(var3(x))
        Next x
        On Error GoTo 0
        Erase var3
        For x = 0 To col.Count - 1
            ReDim Preserve fVar(x): fVar(x) = col(x + 1)
        Next x
        Set col = Nothing
        Sheet3.Range("A2").Resize(x, 1) = Application.Transpose(fVar)
        Erase fVar
    End Sub
    Another method using copy paste & remove duplicates:
    Sub NoDups2()
        Dim rng1 As Range, rng2 As Range
        
        Set rng1 = Application.InputBox(prompt:="Select range 1", Type:=8)
        Set rng2 = Application.InputBox(prompt:="Select range 2", Type:=8)
        rng1.Copy Sheet3.Range("A2")
        rng2.Copy Sheet3.Range("A" & Sheet3.Range("A" & Rows.Count).End(xlUp).Row + 1)
        Sheet3.Range("A:A").RemoveDuplicates 1, xlGuess
    End Sub
    Hope this helps

  4. #4
    Forum Contributor
    Join Date
    05-01-2020
    Location
    CHENNAI
    MS-Off Ver
    EXCEL 2010
    Posts
    105

    Re: List Unique Values from two worksheet in to Results TAB

    Hi CheesSandwich

    Thanks for your help

    I am getting Run time error 424 (Object requied

    Sheet3.Range("A2").Resize(x, 1) = Application.Transpose(fVar)
    I was changed the worksheet name also to "sheet3" still getting this error

  5. #5
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2503
    Posts
    1,459

    Re: List Unique Values from two worksheet in to Results TAB

    How about if the line is:
    Sheets("Sheet3").Range("A2").Resize(x, 1) = Application.Transpose(fVar)

  6. #6
    Forum Contributor
    Join Date
    05-01-2020
    Location
    CHENNAI
    MS-Off Ver
    EXCEL 2010
    Posts
    105

    Re: List Unique Values from two worksheet in to Results TAB

    Hi CheesSandwich

    Thanks its working now as expected

+ 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. [SOLVED] Copy unique values from new data and append to existing list in another worksheet
    By colin_dickson in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-07-2022, 07:15 AM
  2. New: Return multiple results from a unique list
    By ifulao in forum Excel Formulas & Functions
    Replies: 18
    Last Post: 10-03-2018, 03:19 AM
  3. Create a unique list with a count against the unique values
    By barber87 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-12-2017, 10:13 AM
  4. [SOLVED] How to Fill List box on Excel User-Form with Unique Values from Worksheet
    By raghuprabhu in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-12-2017, 05:21 AM
  5. 3 columns: None contain unique values, but I need a list of every unique set
    By mathematician in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 06-15-2012, 04:47 PM
  6. Create list of Unique values based on Worksheet Data
    By todmac in forum Excel General
    Replies: 3
    Last Post: 02-09-2012, 08:17 PM
  7. Find and list only unique results in a column
    By Vbort44 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 07-10-2008, 03:54 PM

Tags for this Thread

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