+ Reply to Thread
Results 1 to 6 of 6

Copying sheets and PasteSpecial

  1. #1
    JRF
    Guest

    Copying sheets and PasteSpecial

    The following code fails if autofilter is filtering rows. How do I
    adapt my code to make it work? The goal is to copy a sheet and then
    replace all formuals with values.

    Sheets(strSheetName).Copy
    After:=wkbNewWorkbook.Sheets(wkbNewWorkbook.Sheets.Count)
    ActiveSheet.Cells.Copy
    ActiveSheet.Cells.PasteSpecial xlValues


  2. #2
    Don Guillett
    Guest

    Re: Copying sheets and PasteSpecial

    try
    Sheets("Sheet2").Copy Before:=Sheets(2)
    Cells.Copy
    Cells.PasteSpecial Paste:=xlPasteValues
    --
    Don Guillett
    SalesAid Software
    [email protected]
    "JRF" <[email protected]> wrote in message
    news:[email protected]...
    > The following code fails if autofilter is filtering rows. How do I
    > adapt my code to make it work? The goal is to copy a sheet and then
    > replace all formuals with values.
    >
    > Sheets(strSheetName).Copy
    > After:=wkbNewWorkbook.Sheets(wkbNewWorkbook.Sheets.Count)
    > ActiveSheet.Cells.Copy
    > ActiveSheet.Cells.PasteSpecial xlValues
    >




  3. #3
    JRF
    Guest

    Re: Copying sheets and PasteSpecial

    I tried the code as suggested but still got the same error...

    Run-time error '1004':
    The information cannot be pasted because the copy area and the paste
    area are not the same size and shape....

    Again, the problem only occurs when the source sheet has autofiltered
    data.


  4. #4
    Don Guillett
    Guest

    Re: Copying sheets and PasteSpecial

    try this instead

    Sub Macro1()
    x = Cells(Rows.Count, "a").End(xlUp).Row
    Sheets("Sheet2").Copy Before:=Sheets(2)
    Range("a2:b" & x) = Range("a2:b" & x).Value
    ' Cells.Copy
    ' Cells.PasteSpecial Paste:=xlPasteValues
    End Sub

    --
    Don Guillett
    SalesAid Software
    [email protected]
    "JRF" <[email protected]> wrote in message
    news:[email protected]...
    >I tried the code as suggested but still got the same error...
    >
    > Run-time error '1004':
    > The information cannot be pasted because the copy area and the paste
    > area are not the same size and shape....
    >
    > Again, the problem only occurs when the source sheet has autofiltered
    > data.
    >




  5. #5
    JRF
    Guest

    Re: Copying sheets and PasteSpecial

    I ended up copying out the autofilter to an array, turning off
    autofilter, copying the sheet, then copyinging back in the array, then
    turning autofiler back on. It took a bit but it works well. Thanks for
    your help.


  6. #6
    Don Guillett
    Guest

    Re: Copying sheets and PasteSpecial

    Try what I did. It tested well.

    --
    Don Guillett
    SalesAid Software
    [email protected]
    "JRF" <[email protected]> wrote in message
    news:[email protected]...
    >I ended up copying out the autofilter to an array, turning off
    > autofilter, copying the sheet, then copyinging back in the array, then
    > turning autofiler back on. It took a bit but it works well. Thanks for
    > your help.
    >




+ 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