[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Move Sheet If It Exists

Posted on 2009-04-01
4
Medium Priority
?
191 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

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

656 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