-
Solved: Sort All sheets in a workbook
Hi
I have below code, which I expect to sort all the sheets in a workbook, however its not working in all worksheets.
Please help me in rectifying this code.
[VBA]
Sub Sorty()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
With Range("E1").Select
Range("A:Z").Sort Key1:=Range("E2"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End With
On Error Resume Next
Next ws
End Sub
[/VBA]
-
[vba]
Sub Sorty()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Select
Range("A:Z").Sort Key1:=Range("E2"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
On Error Resume Next
Next ws
End Sub
[/vba]
-
Thank you very much Patel, code is working as intended, however I made little change
instead of
[VBA]
ws.select
[/VBA]
[VBA]
ws.activate
[/VBA]
-
-
Hi Patel,
with "ws.Select" code was sorting only one sheet, not all the sheets,
hence I tried "ws.activate" which worked as intended
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules