derek.hughes
Board Regular
- Joined
- Mar 16, 2012
- Messages
- 53
I have a workbook with multiple sheets of data and all are in the same format (data with the same headers in columns A:I). However, the number of rows with data is a variable - different for each sheet.
I want it to sort column A ascending and column I descending, and then remove duplicates - for each sheet in the workbook. I keep getting a debug on this line:
".SetRange ActiveCell.Offset(-1, 0).Range("A1:I731")"
How do I resolve this? Thanks!
Derek
I want it to sort column A ascending and column I descending, and then remove duplicates - for each sheet in the workbook. I keep getting a debug on this line:
".SetRange ActiveCell.Offset(-1, 0).Range("A1:I731")"
How do I resolve this? Thanks!
Derek
Code:
Sub Sort()'
' Sort Macro
'
'
Dim wsheet As Worksheet
For Each wsheet In ActiveWorkbook.Worksheets
Sheets(wsheet.Name).Select
ActiveCell.Cells.Select
ActiveSheet.Sort.SortFields.Clear
ActiveSheet.Sort.SortFields.Add Key:=ActiveCell.Range( _
"A1:A730"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveSheet.Sort.SortFields.Add Key:=ActiveCell.Offset( _
0, 8).Range("A1:A730"), SortOn:=xlSortOnValues, Order:=xlDescending, _
DataOption:=xlSortNormal
With ActiveSheet.Sort
.SetRange ActiveCell.Offset(-1, 0).Range("A1:I731")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ActiveSheet.Range("$A$1:$I$731").RemoveDuplicates Columns:=1, Header:=xlYes
ActiveCell.Offset(-1, 0).Range("A1").Select
Next wsheet
End Sub
Last edited: