Home

Macro to sort range within a sheet, then re-do for 100+ sheets

lisae
Occasional Visitor

I recorded a macro to highlight a range (A3:J47) in a worksheet (2012_03), then to sort on column J in descending order. The macro performed correctly. I have 100+ identical worksheets that I want to perform this same macro on and I can not get it to work.

 

When I choose a different worksheet (such as 2012_04) and run the macro, only the range is selected, and the sort is performed on the original worksheet (2012_03) but not the active worksheet (2012_04).

 

Help!

 

Here is the VBA code that I can make little sense of (I'm a newbie, obviously):

 

Sub SortRows()
'
' SortRows Macro
'

'
Range("A3:J47").Select
ActiveWorkbook.Worksheets("2012_03").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("2012_03").Sort.SortFields.Add2 Key:=Range("J3:J47" _
), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("2012_03").Sort
.SetRange Range("A3:J47")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
16 Replies
flashing a white screen while open new tab
cntvertex in Discussions on
11 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
28 Replies
Early preview of Microsoft Edge group policies
Sean Lyndersay in Discussions on
65 Replies