PDA

View Full Version : Custom sort modification



preseb
04-21-2011, 10:13 AM
I recoded this macro to help sort specific titles in a explicit order. I would like to change it so that the range is dynamic. the length will not always be the same.
Can anyone help?



ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add Key:=Range("C3:C140") _
, SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:= _
"Medicare Subtotal, Other Medicare HMO Subtotal,Senior Blue Subtotal,Medical Assistance Subtotal,Amerihealth Mercy Subtotal,CCBH Subtotal,Gateway Subtotal,MedPlus Three Rivers Subtotal,Aetna Subtotal,Amerihealth Admin Subtotal,Auto Subtotal,BHP Subtotal,BHP Employee Subtotal,Blue Shield Subtotal,Capital Blue Cross Subtotal,Cigna Subtotal,Health America Subtotal,Independence BC Subtotal,Keystone Central Subtotal,Keystone East Subtotal,Self-Pay Subtotal,United Healthcare Subtotal,Workers Comp Subtotal,Senior Blue" _
, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet2").Sort
.SetRange Range("A3:O140")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

BrianMH
04-21-2011, 10:23 AM
just like in http://www.vbaexpress.com/forum/showthread.php?t=37025

preseb
04-21-2011, 11:12 AM
oops

Simon Lloyd
04-21-2011, 12:34 PM
Preseb, please do not post duplictes when you clearly had an answer there, an administrator had also asked you to surround your code with the VBA tags (as i have done for you in your first post of this thread), please remember next time.

Thread Closed