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:
<tbody>
</tbody>
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
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