Vincent88
Active Member
- Joined
- Mar 5, 2021
- Messages
- 382
- Office Version
- 2019
- Platform
- Windows
- Mobile
Hi Guy,
I want to sort a virtual list. Can someone help me out.
The virtual object list refers to dynamic range in Column L. I want to sort the object list only (not actual list in column L) from A to Z and assign a name to it for dropdown list purpose. What should be corrected ?
I want to sort a virtual list. Can someone help me out.
The virtual object list refers to dynamic range in Column L. I want to sort the object list only (not actual list in column L) from A to Z and assign a name to it for dropdown list purpose. What should be corrected ?
VBA Code:
Sub sortedVirtualListAgent1()
Dim rngSort As Range
Dim lr As Long
Dim Agtarray As Object
Dim rngL As Range
'Creating a array list
Set Agtarray = CreateObject("System.Collections.ArrayList")
'Physical Source in Column L
lr = Sheets("Data").Cells(Rows.Count, "L").End(xlUp).Row
Set rngL = Sheets("Data").Range("L2:L" & lr)
'Set reference to the Table and column to be sorted
Set Agtarray = rngL
'Use Range.Sort method to apply sort
Agtarray.Sort _
Key1:=rngSort, _
Order1:=xlAscending, _
Header:=xlYes
sorted_array = Agtarray.toarray
End Sub