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

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,214,522
Messages
6,120,022
Members
448,939
Latest member
Leon Leenders

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