Sort multiple columns based on the price column

sofas

Well-known Member
Joined
Sep 11, 2022
Messages
559
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
Hello, I have data. [C11:i40] Column H includes prices. I want to sort them. That is, from the smallest price to the largest price in column H using vba code.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Sorry, I did not notice what was required to sort the data by arranging the H column from largest to smallest
 
Upvote 0
The following code sorts the columns ascending. How can I modify it to sort them descending on column H?

Sub Tri_column()
Dim clé() As String, index() As Long, Rng As Range
a = [C11:J38].Value: Set Rng = [C11]
Dim b()
ReDim b(LBound(a) To UBound(a), LBound(a, 2) To UBound(a, 2))
Set rCrit = CreateObject("System.Collections.Sortedlist")
For i = LBound(a) To UBound(a)
rCrit.Add a(i, 7) & i, i
Next i
For tmp = LBound(a) To UBound(a)
For arr = LBound(a, 2) To UBound(a, 2)
b(tmp, arr) = a(rCrit.GetByIndex(tmp - 1), arr)
Next arr
Next tmp
Rng.Resize(UBound(b), UBound(b, 2)).Value2 = b
End Sub
 
Upvote 0

Forum statistics

Threads
1,221,417
Messages
6,159,789
Members
451,589
Latest member
Harold14

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