vba:对组合框中的项进行排序

时间:2017-04-24 19:23:35

标签: excel vba combobox

以下是用于填充仅包含唯一项目的组合框的代码:

Private Sub UserForm_Initialize()

DivisionBox.Clear

Dim LastRow As Long
Dim Rng As Range
Dim Cell As Range

LastRow = Sheets("Active Branch List").Range("B" & Rows.Count).End(xlUp).Row
Set Rng = Sheets("Active Branch List").Range("B3:B" & LastRow)

With CreateObject("Scripting.Dictionary")

For Each Cell In Rng

    If Not .exists(Cell.Value & "-" & Cell.Offset(0, 1).Value) Then
        .Add Cell.Value & "-" & Cell.Offset(0, 1).Value, Nothing
    End If

Next Cell

DivisionBox.List = .keys

End With

End Sub

这完美无缺,除了我希望在添加到组合框之前将键排序为A到Z.我已经搜索了解决方案,但似乎无法将它们用于我已有的代码中。

0 个答案:

没有答案