I am trying to use the below code to create unique and sorted list dropdown inside a combobox list. What I am looking for is a subruoutine with arguments (List Range, Combobox), so that I can reuse the code for multiple comboboxes. How to modify the below code for this. Codes between "Private Sub UserForm_Initialize() .. End Sub" will be reused.
Thanks.
Thanks.
Code:
Option Explicit
Dim FArray()
Dim DataList As Range
Dim MyList As String
Private Sub UserForm_Initialize()
Dim Found As Long, i As Long
Dim cel As Range
'Set Range Name to suit
MyList = "[B]Table_Customer[Customer Name]"[/B]
Set DataList = Range(MyList)
ReDim FArray(DataList.Cells.Count)
i = -1
For Each cel In DataList
On Error Resume Next
Found = Application.WorksheetFunction.Match(CStr(cel), FArray, 0)
If Found > 0 Then GoTo Exists
i = i + 1
FArray(i) = cel
Exists:
Found = 0
Next
ReDim Preserve FArray(i)
Call BubbleSort(FArray)
[B]cmbName[/B].ListRows = i + 1
[B]cmbName[/B].List() = FArray
End Sub
Last edited: