Loop thru and sort cells in rows

kpm30519

New Member
Joined
Nov 9, 2018
Messages
22
Hello-- I have about 2000 rows with values in individual cells. I enter the values in each day, in numerical order, smallest to largest. While taking time off the person doing this for me didn't bother to sort the rows correctly and now they're a mess. I'd like to loop through each row, sort them properly, then move to the next row. I'r really like to use a macro so I'm not sitting here for a week.

My data range starts at (E2:I2) and runs for +/- 2000 rows, always (En:In). I'd like the loop to run until it hits an empty cell in the next row.

Thanks in advance.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
MAybe a small block of sample data....and how you want it sorted ??
 
Upvote 0
<!-- Please do not remove this header --><!-- Table easily created from Excel with ASAP Utilities (https://www.asap-utilities.com) -->
OneTwoThreeFourFive
24111528
813142330
513243545
1012183036
1252345
14374546
612263638
1725363840
13264044
823384041

<tbody>
</tbody>
It's just a simple table of numbers. I'd like lowest value on the left, to highest on the right. The main issue is I have no way of knowing where the un-ordered rows are, or how many there are.
 
Upvote 0
Maybe this thyen...


Code:
Sub Macro1()
Dim r As Long, lr As Long
lr = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
With Range("E2:I" & lr)
     For r = 2 To lr
          .Rows(r).Sort Key1:=.Range("E" & r), Order1:=xlAscending, Orientation:=xlLeftToRight
     Next r
End With
End Sub
 
Upvote 0
Sorry typo...ignore last post
Use this one instead

Code:
Sub MM1()
Dim r As Long, lr As Long
lr = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
With Range("E1:I" & lr)
     For r = 2 To lr
          .Rows(r).Sort Key1:=.Range("E" & r), Order1:=xlAscending, Orientation:=xlLeftToRight
     Next r
End With
End Sub
 
Upvote 0
Sorry typo...ignore last post
Use this one instead

Code:
Sub MM1()
Dim r As Long, lr As Long
lr = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
With Range("E1:I" & lr)
     For r = 2 To lr
          .Rows(r).Sort Key1:=.Range("E" & r), Order1:=xlAscending, Orientation:=xlLeftToRight
     Next r
End With
End Sub



DUDE!!! Thank you! You've saved both my sanity and hours of work!! Michael, you rock!
 
Upvote 0
Glad to help and thx for the fedback...(y)
 
Upvote 0

Forum statistics

Threads
1,213,484
Messages
6,113,923
Members
448,533
Latest member
thietbibeboiwasaco

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