?
Solved

Move Sheet If It Exists

Posted on 2009-04-01
4
Medium Priority
?
188 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1200 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

765 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