-
Solved: Macro to sort data ascending
Each example contains 21 rows starting in row 66. Each example has one ticker that is either Long or Short and 20 tickers that are either a Long Basket or Short Basket.
For each example I would like to sort ascending the 20 tickers that are either a Long Basket or Short Basket.
Any help would be great. Thanks!
-
So you want to sort B66:S86 (equivalent) by column B ascending in each group?
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
-
No. For each group I would like to sort F67:F86 ascending and that is all
-
Part working, no time to figure out the bug!
[VBA]
Sub Dosort()
Dim c As Range, Rng As Range
Set c = Range("A66")
Set Rng = c.Offset(1, 5).Resize(20)
ActiveSheet.Sort.SortFields.Clear
Do
Set Rng = c.Offset(1, 5).Resize(20)
Rng.Select
With ActiveSheet.Sort
.SortFields.Add Key:=Rng(1), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SetRange Rng
.Header = xlNo
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Set c = c.End(xlDown)
Loop Until c.Row = Rows.Count
End Sub
[/VBA]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
-
Thanks but how am I supposed to figure out how to fix the bug? I have no idea!?
-
[VBA]
Option Explicit
Sub Dosort()
Dim c As Range, Rng As Range
Set c = Range("A66")
Set Rng = c.Offset(1, 5).Resize(20)
Do
Set Rng = c.Offset(1, 5).Resize(20)
Rng.Sort Key1:=Rng(1), Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Set c = c.End(xlDown)
Loop Until c.Row = Rows.Count
End Sub
[/VBA]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules