Sort several ranges

EranP

New Member
Joined
Jul 31, 2019
Messages
1
Hi everyone,

I have several ranges in My worksheet. Each range is separated by an empty row .

Each range start With A = 1050

In all ranges A-H column are constant. And I-AT columns are variable.
I need to sort for any range that I-AT columns will be sort by A->Z by columns I.

First table below is wrong and the 2nd is correct.

I will appreciate your help


First table

BUKRSBLARTBLDATBUDATWAERSXBLNRBKTXTXMWSTBSCHL/NEWBSHKONT/NEWKONEWBKWRBTR
1050DZ 02.01.201802.01.2018ILSRC189000002 40112104 50
117000002 50
1050DZ 02.01.201802.01.2018ILSRC189000003 40121009 18
117000002 36
40121009 18

2nd tabl
BUKRSBLARTBLDATBUDATWAERSXBLNRBKTXTXMWSTBSCHL/NEWBSHKONT/NEWKONEWBKWRBTR
1050DZ 02.01.201802.01.2018ILSRC189000002 117000002 50
40112104 50
1050DZ 02.01.201802.01.2018ILSRC189000003 117000002 36
40121009 18
40121009 18

<colgroup><col><col><col span="2"><col><col><col><col><col><col><col><col></colgroup><tbody>
</tbody>
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Assuming your headers are in row 1 and the data starts in row 2, try this:

Code:
Sub Sort_ranges()
  Dim ar As Range, ini As Long
  Application.ScreenUpdating = False
  Range("I" & Rows.Count).End(xlUp)(3).Value = "x"
  ini = 2
  For Each ar In Range("I2", Range("I" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeBlanks)
    Range(Cells(ini, "I"), Cells(ar.Row - 1, "L")).Sort key1:=Range("I" & ini), order1:=xlAscending, Header:=xlNo
    ini = ar.Row + 1
  Next
  Range("I" & Rows.Count).End(xlUp).Value = ""
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,490
Messages
6,113,957
Members
448,535
Latest member
alrossman

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