Solved

Move Sheet If It Exists

Posted on 2009-04-01
4
181 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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

16 Experts available now in Live!

Get 1:1 Help Now