Link to home
Start Free TrialLog in
Avatar of quaziblue
quaziblue

asked on

Move Sheet If It Exists

Hi Experts-

I want to move a sheet if it exists.  I came up with the code below and am curious why it won't work.  Any help would be appreciated.
Dim ws As Worksheet
Dim i As Long
 
    For Each ws In ActiveWorkbook.Worksheets
        If ws.Name = "France" Then
            Sheets("France").Move Before:=Sheets("Germany")
        End If
    Next ws

Open in new window

Avatar of Saurabh Singh Teotia
Saurabh Singh Teotia
Flag of India image

Quazi,
Rather then doing the loop, You can do what you are looking for in simple two commands which is this...
This will even move to the next step even when the worksheet is not there...
Saurabh...

On Error Resume Next
Sheets("France").move before:=Sheets("Germany")

Open in new window

Avatar of quaziblue
quaziblue

ASKER

Thanks Saurabh.  As always, your help is awesome.  Could you give me the full code?  In many ways, I'm still a newbie.  Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Saurabh Singh Teotia
Saurabh Singh Teotia
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perfect solution.  Thanks!