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

LVL 1
quaziblueAsked:
Who is Participating?
 
Saurabh Singh TeotiaConnect With a Mentor Commented:
This the only 2 lines is the full code, It will do what you want. It will move that sheet before worksheet germany. and thanks for the compliment.
0
 
Saurabh Singh TeotiaCommented:
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

0
 
quaziblueAuthor Commented:
Thanks Saurabh.  As always, your help is awesome.  Could you give me the full code?  In many ways, I'm still a newbie.  Thanks.
0
 
quaziblueAuthor Commented:
Perfect solution.  Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.