View Single Post
 
Old 08-10-2011, 06:50 AM
tswiers tswiers is offline Windows XP Office 2007
Novice
 
Join Date: Aug 2011
Posts: 1
tswiers is on a distinguished road
Default Generic range for custom sort macro?

I am trying to sort several sheets 2 columns at a time based on cell color. I have been able to create a macro to accomplish this in one sheet but when I switch to the next sheet it only sorts the original range (ex. column A & B) on the following sheets. Is there a generic range I can use instead of specific range?

Here is my macro code:

Sub colorsort2()
'
' colorsort2 Macro
'
' Keyboard Shortcut: Ctrl+w
'
ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
ActiveWorkbook.ActiveSheet.Sort.SortFields.Add(Act iveCell.Range( _
"A1:A1042"), xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.COLOR _
= RGB(0, 176, 240)
With ActiveWorkbook.ActiveSheet.Sort
.SetRange ActiveCell.Range("A1:B1042")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub


Instead of ActiveCell.Range("A......B....") Is there a generic term like offset or ("2 column:50 row") ?
Just like using ActiveWorkbook.ActiveSheet.Sort instead of ActiveWorkbook.Worksheets("5-3") for example.... which allows me to perform this macro on any sheet, I would like it to perform on any two column section I have selected.
Reply With Quote