sort on not active sheet
Thank you, JE, for your 'With - End With' solution. I've applied it to my
code and it works.
By the way: Its true about the risk that is taken when using such a reserved
word as your own variable, but that doesn't seem to cause any problems so
far. I might shorten it Obj in a later fase.
Merry Christmas.
Peter
"JE McGimpsey" schreef in bericht
...
First, I would never recommend using a reserved word (Object) as a
variable name.
I think the problem is your Key1:=Range("S8") line. If the macro is an a
worksheet module, that range will default to that worksheet's S8. If
it's in a regular code module, it defaults to the ActiveSheet.
This works:
Public Sub SheetSort(sWSName As String)
With Sheets(sWSName)
.Range("A8:S57").Sort _
Key1:=.Range("S8"), _
Order1:=xlAscending, _
Header:=xlGuess, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom
End With
End Sub
|