VBA: Get an unique list in a new sheet named "unique" in a column.

icesanta

Board Regular
Joined
Dec 17, 2015
Messages
65
VBA: Get an unique list in a new sheet named "unique" in a column.
Data is in multiple sheets in each cell.
Some sheets, rows, columns or cells may be empty.
VBA will not work in sheet named "data1" and "data2".
VBA will not override if data exists in "unique" sheet.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hi,

I am not sure I fully understood what you are looking for but maybe this is a good start and easy to adapt to your needs (might have issues with empty cell, simply select the range that you need then)

Code:
Sub MacImportSheets()
  'Copy all sheets to Unique Sheet if different than data1 and data 2
    Sheets("Unique").Activate
    Dim Sht As Worksheet
        For Each Sht In ActiveWorkbook.Worksheets
            If (Sht.Name <> "Unique" And Sht.Name <> "data1" And Sht.Name <> "data2") Then
                Sht.Select
                Range("A1").CurrentRegion.Copy
                Sheets("Unique").Select
                Sheets("Unique").Activate
                Range("A65536").End(xlUp).Offset(1, 0).Select
                ActiveSheet.Paste
                Else
            End If
        Next Sht
    'Erase all duplicates in column A
    Sheets("unique").Select
    ActiveSheet.Range("A:A").RemoveDuplicates Columns:=1, Header:=xlYes
End Sub
 
Last edited:
Upvote 0
hmm..It is not picking data from multiple columns or rows :( [VBA is considering only the 1st column]
The first row must be skipped as its' the header.
Also the result column [That should be the A column only] is starting from A3.
 
Upvote 0
Maybe

Code:
Sub MacImportSheets()
  'Copy all sheets to Unique Sheet if different than data1 and data 2
    Sheets("Unique").Activate
    Dim Sht As Worksheet
        For Each Sht In ActiveWorkbook.Worksheets
            If (Sht.Name <> "Unique" And Sht.Name <> "data1" And Sht.Name <> "data2") Then
                Sht.Select
                Range("A3:A9999").Copy
                Sheets("Unique").Select
                Sheets("Unique").Activate
                Range("A65536").End(xlUp).Offset(1, 0).Select
                ActiveSheet.Paste
                Else
            End If
        Next Sht
    'Erase all duplicates in column A
    Sheets("unique").Select
    ActiveSheet.Range("A:A").RemoveDuplicates Columns:=1, Header:=xlYes
End Sub
[/QUOTE]
 
Upvote 0
To copy entire sheet, use
Code:
Cells.copy

But you can not copy a sheet and paste it somwhere else than A1 without getting an error (as your paste would go out of the sheet). So, if you know you will never get more than 52 columns and 10000 lines, just use
Code:
Range("A1:ZZ10000").copy
or any range that suits you.
 
Upvote 0
[h=2]VBA: Get an unique list in a new sheet named "unique" in a column.[/h]
<acronym title="visual basic for applications">VBA</acronym>: Get an unique list in a new sheet named "unique" in a column.

Data is in multiple sheets in each cell. Some sheets, rows, columns or cells may be empty.

<acronym title="visual basic for applications">The VBA</acronym> will not work in sheet named "data1" and "data2".

<acronym title="visual basic for applications">The VBA</acronym> will not override if data exists in "unique" sheet but will start from the next empty cell of "unique" sheet.
 
Upvote 0

Forum statistics

Threads
1,224,812
Messages
6,181,098
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