LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc
Jim Jim is offline
external usenet poster
 
Posts: 615
Default Sort by column, not range

I'm trying to set up a macro that can be used from multiple workbooks with
the same columns but different worksheet names. The number of rows will also
vary. How can I reference the column rather than the range? I want it to
sort by the Customer column which is the column header for column A. Below
is my current code which references a specific worksheet name and range
(which I'm trying to get away from). I recorded the macro for this code.

Columns("A:A").Select
Selection.FormatConditions.AddUniqueValues

Selection.FormatConditions(Selection.FormatConditi ons.Count).SetFirstPriority
Selection.FormatConditions(1).DupeUnique = xlDuplicate
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Range("A1").Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortField s.Clear

ActiveWorkbook.Worksheets("Sheet1").Sort.SortField s.Add(Range("A2:A251"), _
xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color =
RGB(255, 0 _
, 0)
ActiveWorkbook.Worksheets("Sheet1").Sort.SortField s.Add Key:=Range( _
"A2:A251"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("A1:V251")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A1").Select
End Sub


Thank you,
Jim
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to sort when column is included in range Trudy Excel Discussion (Misc queries) 1 July 8th 08 03:27 PM
Sort a range of data based on another column RobM Excel Discussion (Misc queries) 1 July 13th 07 05:36 AM
formula to match a range(sort) so it matches an external column steveo Excel Discussion (Misc queries) 1 June 26th 06 07:54 AM
formula to sort a range so that it matches the exact rows of a column that is outside that range? steveo Excel Discussion (Misc queries) 1 June 18th 06 02:05 AM
Dynamic column chart - auto sort on data range jimfrog Charts and Charting in Excel 0 March 29th 06 02:45 PM


All times are GMT +1. The time now is 03:40 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"