Move Worksheet

  • Thread starter Thread starter TGalin
  • Start date Start date
T

TGalin

3 worksheets. Named A, B, C. Is there a better way to move them then this?

Sub Macro1()
Sheets("A").Select
Sheets("A").Move After:=Sheets(2)
End Sub
 
I wouldn't select it first.
3 worksheets. Named A, B, C. Is there a better way to move them then this?

Sub Macro1()
Sheets("A").Select
Sheets("A").Move After:=Sheets(2)
End Sub
 
When I use that formula by itself it works now, however when I add it on to
another macro it doesn't work. Any thoughts?
 
Although the formula works by itself when I add it on to another macro
nothing happens. Any thoughts?
 
Maybe you don't have a sheet named "A" in the activeworkbook???

Maybe the activeworkbook has fewer than 2 sheets???

Or maybe the other code is what's causing the trouble.
 
Perhaps it lost something in the paste or, as Dave indicates, you need to
the appropriate workbook is active.

I note that you are using a mix of named sheet and sheet index in your code.
Is this what you intend (i.e The sheet named A will appear second in your
tab order after the code runs). Alternatively did you want it to appear
after another specific sheet? The following might help

You can swap two sheets continuously in the same workbook using the same
code if you use the sheet index rather than the sheet name:

Sub Macro1()
Sheets(1).Move After:=Sheets(2)

End Sub

Run the above several times and note the change in location of your first
two sheets in tab order each time.

Now try
Sub Macro1()
Sheets("Sheet1").Move After:=Sheets("Sheet2")

End Sub

After ensuring you have sheets names Sheet1 and Sheet2 in your workbook.
 
Back
Top