VBA Excel: Transfer unique values / remove duplicates from one column to a new sheet

Hello Experts,

I am looking for a procedure to add to my personal.xlsb. The intention of this procedure is  to report unique values based on a selected column from one sheet and transfer it to another sheet:


1-Display inputbox which says: “Please select one of the cell related to the column that you to transfer unique values.

2-Create “UniqueValues” sheet in order to transfer it unique values from selected column into column A of “UniqueValues” sheet.

3-Check process:

If “UniqueValues” already exist keep it and create a new “UniqueValues(2)

I attached an example file.

If you have questions, please contact me.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Roy CoxGroup Finance ManagerCommented:
Do you want to remove all duplicates or leave one instance behind?
LD16Author Commented:
Remove all duplicate values and keep unique values. If toto is reported more than one or one time it should appears one time in Unique Values shhet.
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You may try something like this...

Sub CreateSheetWithUniqueValues()
Dim wsData As Worksheet, wsUnique As Worksheet
Dim rng As Range
On Error Resume Next
Set rng = Application.InputBox("Please select one of the cell related to the column that you want to get unique values from.", "Select Cell In Target Column!", Type:=8)
If rng Is Nothing Then
    MsgBox "You didn't select any cell.", vbExclamation
    Exit Sub
End If
Set wsData = Sheets("Sheet1")
Set wsUnique = Sheets("UniqueValues")
If wsUnique Is Nothing Then
    Set wsUnique = ThisWorkbook.Sheets.Add(after:=Sheets(ThisWorkbook.Sheets.Count))
    wsUnique.Name = "UniqueValues"
    wsUnique.Copy after:=Sheets(ThisWorkbook.Sheets.Count)
    Set wsUnique = ActiveSheet
End If
wsData.Columns(rng.Column).Copy wsUnique.Range("A1")
wsUnique.Range("A1").CurrentRegion.RemoveDuplicates Columns:=1, Header:=xlYes
MsgBox "Unique Values have been copied to the sheet " & wsUnique.Name & ".", vbInformation, "Done!"
End Sub

Open in new window

Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

LD16Author Commented:
Thank, unable to test it right now. I will keep you informed.
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
No issues. Test it as per your convenience.
LD16Author Commented:
Hello Subodh,

Concerning Set wsData = Sheets("Sheet1") is it possible to use Activesheet instead of "Sheet1"?
This will allows me to use the procedure in different sheets.

Thank you very much for your help.
LD16Author Commented:
I tested the procedure however I don't get UniqueValue sheet when I run the procedure and I select any cell located in Column B of Sheet 1.
Please find attached test file.
Thank you very much for your help.
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
I tested the code and it creates a new sheet called UniqueValues if it is not present in the workbook else it will create a copy of UniqueValues.
I have also tweaked the code so that you can select the cell on any sheet and the code will copy the data from that sheet only.
Set wsData = rng.Parent

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LD16Author Commented:
Thank you very much. I tested and it works.
Thank you again for your help!!
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome! Glad it worked as desired.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.