Moving / sorting sheets in VBA

  • Thread starter Michael Beckinsale
  • Start date
M

Michael Beckinsale

Hi All,

I have a series of identical sheets named LN1, LN2 etc up to LN20. They are
sandwiched between sheets "start" & "end" and each cell is summed using
=SUM(LN1:Ln2!A1) etc.

The user has been given the functionality to remove (say LN2, LN3, LN4) from
the protfolio by moving the sheets outside the "start" & "end" sandwich.

The problem l am having is writing some code to re-insert the sheets between
"start" & "end" and keep the numerical order intact.

Has anybody got any ideas?

All suggestions gratefully received

Regards


Michael beckinsale
 
N

Nigel

This will do it for the references you gave.....

Sub SortSheets()
Dim xs As Integer
Application.ScreenUpdating = False
Sheets("LN1").Move After:=Sheets("start")
For xs = 1 To 19
Sheets("LN" & xs + 1).Move After:=Sheets("LN" & xs)
Next
Sheets("end").Move After:=Sheets("LN20")
Application.ScreenUpdating = True
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top