excel - Sort Combobox VBA -
I was wondering how to sort values in a blanket.
I use the combo box when I disable the form because the number of values continuously increases on one sheet.
I use the following code to add items:
Lastcell = ThisWorkbook Sheet ("1") with the combo box. Range ("F1000000"). End (xlUp) .ow + 1 = 2 i .addItem to finalcell thisWorkbook.Sheets ("1"). Cells (i, 6) Next I end with I would like to add a thought to copy those values in a sheet on which I Comocoks and bring them into a new sheet, it's okay Works, but it does not look like a smart option, which means that I make another sheet and then copy the values and sort them instead of sorting them.
My question is, how do anyone directly with the original sheet? I do not know anything of the API, please, only VBA code I am checking on ARDS MSDN but I did not know how to work it.
Thanks and if more information is needed, please let me know.
PS: I they can not sort directly from the original letter because this sheet must be accompanied by a steady command
You can read values from sheets in an array, sort it with code, and then add items.
This code will do this using a Kvikoort: the
dim Private Sub UserForm_Initialize () as long as the dim varRange () version dim lngLastRow I Find long as lngLastRow = range (. F: F ') (what: = "*", SearchOrder: = xlByRows, SearchDirection: = xlPrevious) .Row varRange = range. ( "F: F ') Resize (lngLastRow) .Cells subQuickSort varRange Me.ComboBox1.List = varRange in End Sub Public Sub subQuickSort (var1 version _ long = -1 as the optional ByVal lngLowStart, _ optional ByVal lngHighStart to = -1) long dim lngHigh as variant dim lngLow as dim varPivot long lngLowStart = IIf (lngLowStart = -1, LBoun D (var1), lngLowStart) lngHighStart = IIf (lngHighStart = -1, UBound (var1), lngHighStart) lngLow = lngLowStart lngHigh = lngHighStart varPivot = var1 ((lngLowStart + lngHighStart) \ 2, 1) while (lngLow & lt; = lngHigh) while (var1 (lngLow, 1) & lt; VarPivot and lngLow & Lt; lngHighStart) while lngLow = lngLow + 1 passes (varPivot & lt; var1 (lngHigh, 1) lngHigh & gt; lngLowStart) lngHigh = lngHigh - 1 pass then (lngLow & lt; = lngHigh) then subSwap var1, lngLow, lngHigh lngLow = lngLow + 1 lngHigh = lngHigh - 1 End If Wend so (lngLowStart & LT; lngHigh) again subQuickSort var1, lngLowStart, lngHigh end if (lngLow & LT; lngHighStart) then subQuickSort var1, lngLow, the other end of lngHighStart end in sub private sub subSwap (as bridesmaid variant, lngItem1 long, as long lngItem2) dim varTemp version as the varTemp = var (lngItem1, 1) God (lngItem1, 1) var = (lngItem2, 1) God (lngItem2, 1) = varTemp End Sub
Comments
Post a Comment