["VBA"] Sort rows

montecarlo2012

Well-known Member
Joined
Jan 26, 2011
Messages
984
Office Version
  1. 2010
Platform
  1. Windows
Hi. I am trying to sort some row from smallest to largest but excel looks like support only vertical data.
I have more than 7000 rows, but in random order,
my array is B2:F8905
this is a tiny example of what I have
1597100524660.png


and this is the expecting results:

1597100592095.png


most of the examples I tried do not work, like this
VBA Code:
Sub So()

Dim ws As Worksheet
Dim Rng As Range
Set ws = Worksheets("Sheet1")
Set Rng = ws.Range("B2:F8905")

Rng.Sort Key1:=Range("2:2"), Order1:=xlAscending
End Sub
I know I am missing something, but
Thanks guys.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Try this:

VBA Code:
Sub Addto6_49()
Dim ws As Worksheet
Dim Rng As Range
Dim r As Long
Set ws = Worksheets("Sheet1")

r = 2
For r = 2 To ws.UsedRange.Rows.Count
Set Rng = ws.Range("B" & r & ":F" & r)
Rng.Sort Key1:=Rng, Order1:=xlAscending
Next r

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,990
Messages
6,122,626
Members
449,094
Latest member
bsb1122

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