+ Reply to Thread
Results 1 to 6 of 6

Loop through all Sheets, PasteValues

Hybrid View

  1. #1
    Registered User
    Join Date
    07-30-2007
    Posts
    61

    Question Loop through all Sheets, PasteValues

    Hi

    Please could someone help with the code for looping through ALL the sheets in a workbook, copying ALL the cells and pasting the values?

    Many thanks

    Roasty
    Last edited by roasty_1; 10-29-2008 at 09:17 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Courtesy of Aaron Blood

    Sub Formula_Zapper() 
        Worksheets.Select 
        Cells.Select 
        Selection.Copy 
        Selection.PasteSpecial Paste:=xlPasteValues 
        ActiveSheet.Select 
        Application.CutCopyMode = False 
    End Sub
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    07-30-2007
    Posts
    61
    Thanks, I tried this but I kept getting an error:

    Run-time error '1004';
    Method 'Select' of object 'sheets' failed

    why is this?

    thanks

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Have you hidden sheets?

  5. #5
    Registered User
    Join Date
    07-30-2007
    Posts
    61
    Quote Originally Posted by royUK View Post
    Have you hidden sheets?
    Unhide all the sheets, code now works

    Thanks

    Roasty
    Last edited by roasty_1; 10-28-2008 at 12:07 PM.

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Try this
    Option Explicit 
     
    Sub Formula_Zapper_MkII() 
         
        Dim sh As Worksheet, HidShts As New Collection 
        For Each sh In ActiveWorkbook.Worksheets 
            If Not sh.Visible Then 
                HidShts.Add sh 
                sh.Visible = xlSheetVisible 
            End If 
        Next sh 
         
        Worksheets.Select 
        Cells.Select 
        Selection.Copy 
        Selection.PasteSpecial Paste:=xlPasteValues 
        ActiveSheet.Select 
        Application.CutCopyMode = False 
         
        For Each sh In HidShts        
            sh.Visible = xlSheetHidden 
        Next sh 
         
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1