Sort Rows - Variable Row numbers

FalconFlyer

New Member
Joined
May 18, 2015
Messages
30
I am looking to sort rows of varying quantity. It could be C5:D10 or C11:D20, etc... I have the code to select the proper ranges, but am having trouble with the sort code. My data is setup as follows:

A
B
C
D
1
abc
ddd
3
2
eee
5
3
def
abc
10
4
ggg
20

<tbody>
</tbody>


Code:
Sub Test2()
Range("B1").Select
With ActiveSheet.Range("B:B")
    Set c = .Find(What:="*", LookIn:=xlValues)
    
    If Not c Is Nothing Then
            firstaddress = c.Address
            Set d = .Find(What:="*", After:=c, LookIn:=xlValues)
            secondAddress = d.Address
                Do
                Set rangetosort = Rows(c.Offset(0, 0).Row & ":" & d.Offset(-1, 0).Row)
                rangetosort.Select
                rTwo = d.Offset(-1, 2).Address
                rOne = c.Offset(0, 1).Address
                
            Set c = .FindNext(c)
            Set d = .FindNext(d)
            If c Is Nothing Or d Is Nothing Then
        GoTo DoneFinding
        End If
        Loop While c.Address <> firstaddress
        End If
DoneFinding:
    End With
End Sub

I want to sort the (rOne:rTwo) by Column D. For example, sort C1:D2 by Column D. Next group would be C3:D4.

I hope I am clear. TIA
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Forum statistics

Threads
1,144,693
Messages
5,725,796
Members
422,640
Latest member
KazPL

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
Top