Hi all
I have the following code that adds a new item to a combobox list
Private Sub ConfirmNew_Click()
Dim idx As Variant
Dim rng As Range
With Worksheets("Module Data")
Set rng = .Range("B2", .Range("B" & Rows.Count).End(xlUp))
End With
idx = Application.Match(NewGarage.Value, rng, 1)
If Not IsError(idx) Then
rng.Cells(idx + 1, 1).Insert xlShiftDown
rng.Cells(idx + 1, 1).Value = NewGarage.Value
Garage.List = rng.Value
End If
End Sub
The list of Garage names is in sheet "Module Data". A new Garage name can be inserted in a Textbox "NewGarage".
The code successfully inserts a new name in alphabetical order.
However, if the new name is above the first alphabetically listed name, it gives an error (2042). The workround that I did was to put a dummy name "AAAAAAA" first in the list and the code works.
Can anyone suggest why this is so and what can be changed in the code to add the new name at the top?
Thanks
Bookmarks