Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Unable to sort when column is included in range | Excel Discussion (Misc queries) | |||
Sort a range of data based on another column | Excel Discussion (Misc queries) | |||
formula to match a range(sort) so it matches an external column | Excel Discussion (Misc queries) | |||
formula to sort a range so that it matches the exact rows of a column that is outside that range? | Excel Discussion (Misc queries) | |||
Dynamic column chart - auto sort on data range | Charts and Charting in Excel |