Unique list from 12 tabs data?

MOB

Well-known Member
Joined
Oct 18, 2005
Messages
1,066
Office Version
  1. 365
Platform
  1. Windows
I have 12 tabs - Jan - Dec

On each tab starting cell B6 downwards (with gaps) there will be a customer reference eg AA123456

On a summary tab I want a macro that will pull all of the references from the 12 tabs, and create a unique list. So I can then Vlookup to all 12 tabs.

How can I do this?

TIA
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hi,

Here is a macro from my personal.xls - it requires/allows manual intervention:

Code:
Sub GetUniquesMultipleColumns()
'prompts for you to click the top item of your list and click OK, then repeat for each list
'when no more lists to add, click cancel
'then click on the cell where your output range should begin and click OK
    Dim Rng As Range, Dn As Range, objDict As Object, varVal As Variant
    Set objDict = CreateObject("scripting.dictionary")
    With objDict
        .comparemode = vbTextCompare
        Do
            On Error Resume Next
            Set Rng = Nothing
            Set Rng = application.InputBox("Click the top-most item of the next column to compare.", "Select Input Range", Type:=8)
            If Rng Is Nothing Then Exit Do
            Set Rng = Rng.Parent.Range(Rng, Rng.Parent.Cells(Rows.Count, Rng.Column).End(xlUp))
            For Each Dn In Rng
                'put an apostrophe in front of the value if it appears to be number stored as text - unless it's a boolean
                If VarType(varVal) <> vbBoolean Then
                    varVal = Dn.Value
                    varVal = CDbl(Dn.Value)
                    varVal = IIf(Len(Dn.Value) <> Len(varVal), "'" & Dn.Value, Dn.Value)
                End If
                'add the value to the dictionary
                If Not .exists(Dn.Value) Then .Add Key:=varVal, Item:=Dn.Next.Value
            Next
            On Error GoTo 0
            If MsgBox("Do you want to add to your data set?", vbQuestion + vbYesNo + vbDefaultButton2, "More Data?") = vbNo Then Exit Do
        Loop
        Set Rng = Nothing
        On Error Resume Next
        If .Count = 0 Then Exit Sub 'objDict.Count = 0 would mean no values are in the dictionary
        Set Rng = application.InputBox("Click the cell where you want the unique list to begin.", "Select Output Range", Type:=8).Resize(.Count)
        On Error GoTo 0
        If Rng Is Nothing Then Exit Sub
        Rng.Value = application.Transpose(Array(.keys))
    End With
    'show the range where the unique list was just placed
    Rng.Parent.Parent.Activate
    Rng.Parent.Activate
    If MsgBox("Do you want to sort the unique list?", vbYesNo, "Sort List?") = vbYes Then Rng.Sort Key1:=Rng(1), Order1:=xlAscending, Header:=xlNo
End Sub

Here is a slightly altered version that might be easy to tweak for what you want (look at the sheet numbers, that's probably what you have to change "for i = 1 to 12"):
Code:
Option Explicit


Sub GetUniquesMultipleColumnsNoClicking()
'prompts for you to click the top item of your list and click OK, then repeat for each list
'when no more lists to add, click cancel
'then click on the cell where your output range should begin and click OK
    Dim i As Integer
    Dim Rng As Range, Dn As Range, objDict As Object, varVal As Variant
    Set objDict = CreateObject("scripting.dictionary")
    With objDict
        .comparemode = vbTextCompare
        For i = 1 To 12
            On Error Resume Next
            Set Rng = Nothing
            Set Rng = Sheets(i).Range("B6")
            Set Rng = Rng.Parent.Range(Rng, Rng.Parent.Cells(Rows.Count, Rng.Column).End(xlUp))
            For Each Dn In Rng
                'put an apostrophe in front of the value if it appears to be number stored as text - unless it's a boolean
                If VarType(varVal) <> vbBoolean Then
                    varVal = Dn.Value
                    varVal = CDbl(Dn.Value)
                    varVal = IIf(Len(Dn.Value) <> Len(varVal), "'" & Dn.Value, Dn.Value)
                End If
                'add the value to the dictionary
                If Not .exists(Dn.Value) Then .Add Key:=varVal, Item:=Dn.Next.Value
            Next
            On Error GoTo 0
        Next
        Set Rng = Nothing
        On Error Resume Next
        If .Count = 0 Then Exit Sub 'objDict.Count = 0 would mean no values are in the dictionary
        Set Rng = Application.InputBox("Click the cell where you want the unique list to begin.", "Select Output Range", Type:=8).Resize(.Count)
        On Error GoTo 0
        If Rng Is Nothing Then Exit Sub
        Rng.Value = Application.Transpose(Array(.keys))
    End With
    'show the range where the unique list was just placed
    Rng.Parent.Parent.Activate
    Rng.Parent.Activate
    If MsgBox("Do you want to sort the unique list?", vbYesNo, "Sort List?") = vbYes Then Rng.Sort Key1:=Rng(1), Order1:=xlAscending, Header:=xlNo
End Sub
 
Upvote 0
Here's another option.
If I understand you correctly what you want is make a unique list of values from cell B6 downward in 12 tabs.
Assuming that there are only 13 tabs exist in the workbook (the 12 tabs + tab "Summary"), try this:

Code:
[B][COLOR=Royalblue]Sub[/COLOR][/B] a1078540a()
[I][COLOR=seagreen]'https://www.mrexcel.com/forum/excel-questions/1078540-unique-list-12-tabs-data.html[/COLOR][/I]

[B][COLOR=Royalblue]Dim[/COLOR][/B] ws [B][COLOR=Royalblue]As[/COLOR][/B] Worksheet, d [B][COLOR=Royalblue]As[/COLOR][/B] [B][COLOR=Royalblue]Object[/COLOR][/B], i [B][COLOR=Royalblue]As[/COLOR][/B] [B][COLOR=Royalblue]Long[/COLOR][/B], va
  
     [B][COLOR=Royalblue]For[/COLOR][/B] [B][COLOR=Royalblue]Each[/COLOR][/B] ws [B][COLOR=Royalblue]In[/COLOR][/B] ActiveWorkbook.Worksheets
        [B][COLOR=Royalblue]If[/COLOR][/B] ws.name <> [COLOR=brown]"Summary"[/COLOR] [B][COLOR=Royalblue]Then[/COLOR][/B]
            [B][COLOR=Royalblue]With[/COLOR][/B] ws
                [B][COLOR=Royalblue]Set[/COLOR][/B] d = CreateObject([COLOR=brown]"scripting.dictionary"[/COLOR])
                d.CompareMode = vbTextCompare
                va = .Range([COLOR=brown]"B6"[/COLOR], .Cells(.Rows.count, [COLOR=brown]"B"[/COLOR]).[B][COLOR=Royalblue]End[/COLOR][/B](xlUp))
                    [B][COLOR=Royalblue]For[/COLOR][/B] i = [COLOR=crimson]1[/COLOR] [B][COLOR=Royalblue]To[/COLOR][/B] UBound(va, [COLOR=crimson]1[/COLOR])
                        d(Trim(va(i, [COLOR=crimson]1[/COLOR]))) = [COLOR=brown]""[/COLOR]
                    [B][COLOR=Royalblue]Next[/COLOR][/B]
            [B][COLOR=Royalblue]End[/COLOR][/B] [B][COLOR=Royalblue]With[/COLOR][/B]
        [B][COLOR=Royalblue]End[/COLOR][/B] [B][COLOR=Royalblue]If[/COLOR][/B]
     [B][COLOR=Royalblue]Next[/COLOR][/B]

Sheets([COLOR=brown]"Summary"[/COLOR]).Range([COLOR=brown]"A1"[/COLOR]).Resize(d.count, [COLOR=crimson]1[/COLOR]) = Application.Transpose(Array(d.Keys))

[B][COLOR=Royalblue]End[/COLOR][/B] [B][COLOR=Royalblue]Sub[/COLOR][/B]
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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