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

[TABLE="width: 1011"]
<colgroup><col><col><col span="2"><col><col><col><col><col><col><col><col></colgroup><tbody>[TR]
[TD]BUKRS[/TD]
[TD]BLART[/TD]
[TD]BLDAT[/TD]
[TD]BUDAT[/TD]
[TD]WAERS[/TD]
[TD]XBLNR[/TD]
[TD]BKTXT[/TD]
[TD]XMWST[/TD]
[TD]BSCHL/NEWBS[/TD]
[TD]HKONT/NEWKO[/TD]
[TD]NEWBK[/TD]
[TD]WRBTR[/TD]
[/TR]
[TR]
[TD]1050[/TD]
[TD]DZ [/TD]
[TD]02.01.2018[/TD]
[TD]02.01.2018[/TD]
[TD]ILS[/TD]
[TD]RC189000002[/TD]
[TD] [/TD]
[TD] [/TD]
[TD]40[/TD]
[TD]112104[/TD]
[TD] [/TD]
[TD]50[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD]11[/TD]
[TD]7000002[/TD]
[TD] [/TD]
[TD]50[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]1050[/TD]
[TD]DZ [/TD]
[TD]02.01.2018[/TD]
[TD]02.01.2018[/TD]
[TD]ILS[/TD]
[TD]RC189000003[/TD]
[TD] [/TD]
[TD] [/TD]
[TD]40[/TD]
[TD]121009[/TD]
[TD] [/TD]
[TD]18[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD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D] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]1050[/TD]
[TD]DZ [/TD]
[TD]02.01.2018[/TD]
[TD]02.01.2018[/TD]
[TD]ILS[/TD]
[TD]RC189000003[/TD]
[TD] [/TD]
[TD][/TD]
[TD]11[/TD]
[TD]7000002[/TD]
[TD] [/TD]
[TD]36[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD]40[/TD]
[TD]121009[/TD]
[TD] [/TD]
[TD]18[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD]40[/TD]
[TD]121009[/TD]
[TD] [/TD]
[TD]18[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
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,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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