How to sort data using a custom list which contains numbers using VBA?

Pramodpandit123

New Member
Joined
Apr 18, 2020
Messages
30
Office Version
  1. 2016
Platform
  1. Windows
I have a Custom List made which contains Numbers only and when I try to sort the Data's using the Custom List, it simply sorts the Data's in Ascending/Descending order and does not sort based on the arrangement of Custom List. How do we sort the data using a Custom List containing Numbers only.

The idea that i came up with is to add a string to the Custom List data as well as data that need to be sorted and then sort it.
Is it possible to sort data's without changing/adding anything in active worksheet ?

Link to sample file : Samplenew.xlsm
While trying the sample file: Try using both Numeric and String column data ! Replace the Blue colored cells on both sheets with Numeric and String column data !After that run the macro and you'll see that Numeric data will sort on ascending order irrespective to Custom list where as String data will sort based on Custom list.

Crossposted at- How to sort data using a custom list which contains numbers using VBA?
 

Attachments

  • Capture.JPG
    Capture.JPG
    59.6 KB · Views: 18

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Not sure what you are looking for.

Can you post your starting data, the result you get, the result you want it to be.
 
Upvote 0
How about
VBA Code:
Sub Sample()
Set rng1 = Sheet1.Range("A4", Sheet1.Range("X" & Rows.Count).End(xlUp))
Set rng2 = Sheet2.Range("M10", Sheet2.Range("M10").End(xlDown))

lst = Join(Application.Transpose(rng2.Value2), ",")
With Sheet1.Sort
   .SortFields.Clear
   .SortFields.Add Range("a4"), , , CStr(lst)
   .SetRange rng1
   .Header = xlNo
   .Apply
   End With
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top