?
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
Medium Priority
?
348 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 2000 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
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.

777 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