JimS
07-30-2009, 12:43 PM
I need to sort several worksheets within an active workbook.
I was thinking of creating the sort order on a sheet named "Order" (cell A1:??). I will create this sort order list with some formulas so the code would need to ignore formulas (or delete any formulas first).
I have found the code below but cannot get it to work.
It always fails on: Worksheets(.Cells(Ndx).Value).Move before:=Worksheets(1)
I haven't tried to use a dynamic range name yet - wanted to make sure this code worked first.
My Workbook has Charts in it - would that make a difference?
Any ideas?
Thanks...
Jim
Sub SortWS2()
Dim SortOrder As Variant
Dim sheetsorder As Range
Dim Ndx As Long
Application. ScreenUpdating (http://vbaexpress.com/forum/) = False
With Worksheets("Sort Order").Range("A1:A79")
For Ndx = .Cells.Count To 1 Step -1
Worksheets(.Cells(Ndx).Value).Move before:=Worksheets(1)
Next Ndx
End With
Application.ScreenUpdating = True
End Sub
I was thinking of creating the sort order on a sheet named "Order" (cell A1:??). I will create this sort order list with some formulas so the code would need to ignore formulas (or delete any formulas first).
I have found the code below but cannot get it to work.
It always fails on: Worksheets(.Cells(Ndx).Value).Move before:=Worksheets(1)
I haven't tried to use a dynamic range name yet - wanted to make sure this code worked first.
My Workbook has Charts in it - would that make a difference?
Any ideas?
Thanks...
Jim
Sub SortWS2()
Dim SortOrder As Variant
Dim sheetsorder As Range
Dim Ndx As Long
Application. ScreenUpdating (http://vbaexpress.com/forum/) = False
With Worksheets("Sort Order").Range("A1:A79")
For Ndx = .Cells.Count To 1 Step -1
Worksheets(.Cells(Ndx).Value).Move before:=Worksheets(1)
Next Ndx
End With
Application.ScreenUpdating = True
End Sub