Delete Duplicate Data for a combo box

Mileshigh

Board Regular
Joined
Oct 1, 2008
Messages
54
Ok so i have a list of supplier in column A that start in A2 and go down as new rows are always added. What i cant seem to work is i want to select all entrys from A2 down and paste them is lets say sheet2 and then remove duplicate names. Once only one of each company name is left i want to name that range: "comp" and use it for a combo box list.

I understand how to populated the combo list and how to copy the data to sheet2 just not delete the duplicate names leaving only one of each name...and then get the range named.

Like I said new company names are added so i need this to dynamic...i got the code working to remove the prior named ranges already workin

thanks
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Try this

Code:
Sub Unique()
Dim s1 As Worksheet: Set s1 = ActiveWorkbook.Sheets("Sheet1") 'source sheet
Dim s2 As Worksheet: Set s2 = ActiveWorkbook.Sheets("Sheet2") 'target sheet
Dim Col1 As Long: Col1 = 1 'source sheet
Dim Col2 As Long: Col2 = 1 'target sheet
Dim FR1 As Long: FR1 = 2 'source sheet
Dim FR2 As Long: FR2 = 1 'target sheet
Dim LR As Long: s1.Select: LR = s1.Cells(s1.Rows.Count, Col1).End(xlUp).Row 'source sheet
Dim i As Long
Dim Collect As New Collection
Dim RngName As String: RngName = "comp"
On Error Resume Next
For i = FR1 To LR
      Collect.Add s1.Cells(i, Col1), CStr(s1.Cells(i, Col1))
Next i
On Error GoTo 0
For i = 1 To Collect.Count
      s2.Cells(FR2 + i - 1, Col2) = Collect(i)
Next i
s2.Range(s2.Cells(FR2, Col2), s2.Cells(FR2 + Collect.Count - 1, Col2)).Name = RngName
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,286
Members
452,902
Latest member
Knuddeluff

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