Auto sort three separate ranges within the same column

MTBAha

New Member
Joined
Jun 21, 2018
Messages
4
Hello,

I found this VBA that auto sorts a Multiple Column Groups Separately.
____________________________________________
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)


Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Column = 1 Then

Range("A5:B50").Sort _

Key1:=Range("A5"), Order1:=xlAscending, _
Key2:=Range("B5"), Order2:=xlAscending, _
Header:=xlYes, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom

ElseIf Target.Column = 3 Then


Range("C5:D50").Sort _

Key1:=Range("C5"), Order1:=xlAscending, _
Key2:=Range("D5"), Order2:=xlAscending, _
Header:=xlYes, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom


End If
End Sub
__________________________________________

But I need to auto sort two separate ranges within the same column like in the image below.

1Cell ACell BCell C
2ProductOrder StatusExpiration Date
3CarrotPending
4OrangePending
5PepperComplete2018/12/20

<tbody>
</tbody>

Need to be able to auto sort another table located below

Cell ACell BCell C
6ProductOrder StatusExpiration Date
7ApplePending
8PearComplete2018/10/15
9OnionComplete2018/12/25

<tbody>
</tbody>

Please help with VBA code.

Thank you!
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Try creating a macro via the macro recorder.
 
Upvote 0
Hi,

Thanks for your response!

I tried it, but it doesn't work. What it does just selects the range of cells (I assume it's the first action of the macros I recorded). Is it at all possible to sort two separate ranges within the same column and the same sheet?
 
Upvote 0
The macro recorder records only what you do.
Turn on the recorder, perform all the stuff you want to do, turn off the recorder.
 
Upvote 0
Hi,

It recorded every step, but when I apply it to the button it only does the first line and stops. Is it possible at all to sort two different ranges within the same column?

I appreciate your response.
 
Upvote 0
If col A is values, not formulas & you have blank rows between sections. Try
Code:
Sub SortGroups()
   Dim Rng As Range
   
   For Each Rng In Range("A:A").SpecialCells(xlConstants).Areas
      Rng.CurrentRegion.Sort key1:=Rng.Resize(1, 1), order1:=xlAscending, header:=xlYes, MatchCase:=False
   Next Rng
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,868
Members
449,054
Latest member
juliecooper255

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