Solved

Move Sheet If It Exists

Posted on 2009-04-01
4
180 Views
Last Modified: 2013-11-25
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

0
Comment
Question by:quaziblue
  • 2
  • 2
4 Comments
 
LVL 59

Expert Comment

by:Saurabh Singh Teotia
ID: 24042026
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
 
LVL 1

Author Comment

by:quaziblue
ID: 24042289
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
 
LVL 59

Accepted Solution

by:
Saurabh Singh Teotia earned 300 total points
ID: 24042299
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
 
LVL 1

Author Closing Comment

by:quaziblue
ID: 31565457
Perfect solution.  Thanks!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now