The below code basically looks at a source sheet on workbook open, takes the values from a range and loops through adding each value to a combobox.
What I want to do is include some code to ensure only unique values, i.e. no dupes, are added.
Any ideas how I can get that working?
Thanks!
Private Sub Workbook_Open() Dim wb As Workbook Set wb = ThisWorkbook Dim Home As Worksheet Dim Datasource As Worksheet 'Define Variables and dropdown object Dim LastRow As Long Dim MIDCell As Range Dim ComboMID As ComboBox Set Home = ActiveSheet Set Home = Worksheets("UPDATER") Set Datasource = wb.Sheets("LaunchCodes") 'asign dropdown object to combobox Set ComboMID = Home.OLEObjects("ComboBox1").Object 'Empty the combobox currnetly to avoid duplicating content ComboMID.Clear 'With and For loop to put all values in games launch code column, ignoring any blanks, into combobox With Datasource LastRow = .Cells(.Rows.Count, "D").End(xlUp).Row For Each MIDCell In .Range("D2:D1000" & LastRow) If MIDCell.Value <> "" Then ComboMID.AddItem MIDCell.Value End If Next End With End Sub https://stackoverflow.com/questions/65589051/vba-only-add-unique-values-to-excel-combobox-which-is-populated-by-looping-thr January 06, 2021 at 09:41AM
没有评论:
发表评论