+ Reply to Thread
Results 1 to 5 of 5

Copy & PasteSpecial issue

Hybrid View

  1. #1
    Registered User
    Join Date
    01-29-2012
    Location
    sydney
    MS-Off Ver
    Excel 2003
    Posts
    6

    Copy & PasteSpecial issue

    Hi Guys

    I am hoping someone can assist

    I have a Master xls which generates 4x worksheets of "raw data" for importing into a SQL file at the End of the Month.

    I have generated the code below to copy the required worksheets from the master file and create a new file with only the four worksheets, (this works 100% fine) the problem is that when it copies the worksheets into a new workbook, the cells are still linked to the master.

    I need the data in the new worksheets to be only values and formats as the file is to be emailed for uploading - but I couldnt work out a way to do that! I attempted to copy / pastespecial the cells after the new file was created however it crashes with Cells.Select command.

    Can anyone provide some guidance? Perhpas a way to create the the new file with vlaues / formats only OR a correct bit of code to copy/ paste special in the new worksheet.


    Grateful for any assistance
    Boris.

        ' get name to save new workbook as. change reference as needed
        strSaveName = TargetFilePath + "BSC SQL Import File for Month of " & BSCM & " " & BSCY & ".xls"
             
        ' copy sheets to new workbook
        Sheets(Array("BSC SQL Import-Labels(Nat-Reg)", "BSC SQL Import-Labels(AllWrkGp)", "BSC SQL Import(NationalRegions)", "BSC SQL Import(ALLWorkgroups)")).Copy
        ActiveWorkbook.SaveAs strSaveName
         
        Sheets(Array("BSC SQL Import-Labels(Nat-Reg)", "BSC SQL Import-Labels(AllWrkGp)", "BSC SQL Import(NationalRegions)", "BSC SQL Import(ALLWorkgroups)")).Select
        Sheets("BSC SQL Import-Labels(Nat-Reg)").Activate
    
        Cells.Select ' IT CRASHES HERE!!!
        
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
            
        ActiveWorkbook.Close

  2. #2
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,276

    Re: Copy & PasteSpecial issue

    Possibly using a variant array will work instead of copy/pastevalues...
        Dim vData            As Variant
        With Sheets("BSC SQL Import-Labels(Nat-Reg)")
            .Activate
            vData = .UsedRange
            .UsedRange = vData
        End With

  3. #3
    Registered User
    Join Date
    01-29-2012
    Location
    sydney
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Copy & PasteSpecial issue

    Dangelor....
    This works perfectly!! I was unsure of how to do it for all sheets effectively but used you code below four times (once for each of the sheets) and it works perfect!!

    Many thanks for the assist! Amazing

    Boris

    Quote Originally Posted by dangelor View Post
    Possibly using a variant array will work instead of copy/pastevalues...
        Dim vData            As Variant
        With Sheets("BSC SQL Import-Labels(Nat-Reg)")
            .Activate
            vData = .UsedRange
            .UsedRange = vData
        End With

  4. #4
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,276

    Re: Copy & PasteSpecial issue

    Glad it worked!

  5. #5
    Registered User
    Join Date
    01-29-2012
    Location
    sydney
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Copy & PasteSpecial issue

    Thanks dangelor -I'll give this a go !!
    Cheers
    Boris

+ 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