Solved

How do you change the order tabs are copied and pasted when using VBA in MS Excel 2010?

Posted on 2014-07-29
3
342 Views
Last Modified: 2014-07-29
Hi All!

I'm hoping there is an easy solution to my issue. I have the code below that is set to go through all sheets in my workbook and copy then paste special values into the same spot. However, my tab that has my pivot table data is getting copied prior to all the other tabs, so my get pivot formulas are erring out because the data is getting pasted as values before the other tabs. I am trying to find a way to have my pivot table copy and paste special *after* all my other tabs. Any thoughts? Here is the VBA I am using to cycle through the tabs:

Sub PasteValues()
    Dim wks As Worksheet
    Dim wb As Workbook
    Set wb = ThisWorkbook
    For Each wks In wb.Worksheets
    wks.Cells.Copy
    wks.Cells.PasteSpecial Paste:=xlValues
    Next
End Sub

If this isn't clear, ask questions and I'll try to explain better. Thanks in advance for everyone's help!

- Dave
0
Comment
Question by:uga_godawgs
[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
3 Comments
 
LVL 27

Accepted Solution

by:
Glenn Ray earned 500 total points
ID: 40227407
You'd just need to add an exception to the For Each...Next loop and then go back to that sheet and do a final value replacement.  Here's an example:
Sub PasteValues()
    Dim wks As Worksheet
    Dim wb As Workbook
    Set wb = ThisWorkbook
    For Each wks In wb.Worksheets
        If wks.Name <> "pivotsheettabname" Then
            wks.Cells.Copy
            wks.Cells.PasteSpecial Paste:=xlValues
        End If
    Next
    With Sheets("pivotsheettabname")
        .Cells.Copy
        .Cells.PasteSpecial Paste:=xlValues
    End With
 End Sub

Open in new window


Regards,
-Glenn
0
 

Author Comment

by:uga_godawgs
ID: 40227463
Glenn - worked perfectly! Definitely a 'Doh!' moment - looked for an over-complicated solution! Thanks for your help!

-Dave
0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40227515
You're welcome.  Sometimes it's a "forest-for-the-trees" thing...happens to me all the time.

-Glenn
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
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!
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

724 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