+ Reply to Thread
Results 1 to 11 of 11

Paste Values vba error (MS Excel 2007)

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-17-2013
    Location
    USA, IL
    MS-Off Ver
    Excel 2010
    Posts
    121

    Paste Values vba error (MS Excel 2007)

    Hi

    I'm not quite proficient in vba's to save my life but I managed to write a simple macro to select and copy and paste special values and format a worksheet that is heavily fortified in formulas. But each time I run the macro it pastes all zero's into a new worksheet instead of values from the original worksheet.
    Basically I would hope the macro does is copy and paste special values into a new workheetsheet and also keeping the same formating. I am not sure where I am going wrong with the macro or how to fix it.

    I will gladly appreciate any advise and assistance;

    Sub TextFile_Annual_Summary()
    
    Dim X As Variant, Y As Variant, T As String
    
    ' TextedFile Macro
    ' Copy Annual Summary into new file and c/p value everything
    '
        application.ScreenUpdating = False
        T = Worksheets("Ref").range("N10")
        X = Worksheets("Ref").range("N10")
        Sheets("Annual Summary").Select
        Sheets("User Input&Pull").Activate
        Sheets("Annual Summary").Copy
    
    Sheets("Annual Summary").Select
        Cells.Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        application.CutCopyMode = False
        Sheets("Annual Summary").Select
        Sheets("Annual Summary").Move After:=Sheets(1)
        Sheets("Annual Summary").Name = X & " Annual Summary"
        application.ScreenUpdating = True
        ActiveWindow.DisplayOutline = False
        range("D7").Select
        
        
        End Sub
    Thank you.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,738

    Re: Paste Values vba error (MS Excel 2007)

    Your code is very confusing. You have named one cell as both a variant and a string. Additionally, you have activated multiple sheets.

    How about telling us exactly what you wish to happen and give us some clear examples so that we can provide you with some clean code that will do exactly what you wish and help you to understand how VBA works. A sample worksheet uploaded with a before and after example will be very helpful.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    883

    Re: Paste Values vba error (MS Excel 2007)

    Cross-posted without a link @
    http://www.mrexcel.com/forum/excel-q...-headache.html
    If my solution worked (or not) please let me know. If your question is answered then please remember to mark it solved

    Computers are like air conditioners. They work fine until you start opening windows. ~Author Unknown

  4. #4
    Forum Contributor
    Join Date
    03-17-2013
    Location
    USA, IL
    MS-Off Ver
    Excel 2010
    Posts
    121

    Re: Paste Values vba error (MS Excel 2007)

    I want the macro to copy data in one worksheet and paste the values into another worksheet. The Worksheet from which the macro is copying data from has formulas and I want it to paste just the values and formatting into a different workksheet..

    Thanks.

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Paste Values vba error (MS Excel 2007)

    I'm confused as well. here's a guess.

    Sub TextFile_Annual_Summary()
    ' TextedFile Macro
    ' Copy Annual Summary into new file and c/p value everything
    '
    
        Application.ScreenUpdating = False
    
        'Copy sheet as new workbook
        Sheets("Annual Summary").Copy
        
        'Rename copied sheet
        ActiveSheet.Name = ThisWorkbook.Sheets("Ref").Range("N10").Text & " Annual Summary"
        
        'Convert formulas to values and keep formats
        ActiveSheet.UsedRange.Value = ActiveSheet.UsedRange.Value
        
        ActiveWindow.DisplayOutline = False
        Range("D7").Select
        
        Application.ScreenUpdating = True
        
    End Sub
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  6. #6
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,738

    Re: Paste Values vba error (MS Excel 2007)

    Your post does not comply with Rule 8 of our Forum RULES. Do not crosspost your question on multiple forums without including links here to the other threads on other forums.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).

  7. #7
    Forum Contributor
    Join Date
    03-17-2013
    Location
    USA, IL
    MS-Off Ver
    Excel 2010
    Posts
    121

    Re: Paste Values vba error (MS Excel 2007)

    My fault. Thanks for the tip.

  8. #8
    Forum Contributor
    Join Date
    03-17-2013
    Location
    USA, IL
    MS-Off Ver
    Excel 2010
    Posts
    121

    Re: Paste Values vba error (MS Excel 2007)

    Thank you AlphaFrog.

    Your code does exactly what I need it to do but like mine when it paste into the new worksheet it's all zero's instead of actual values. I appreciate the assistance.

    I tried wrtting a simpler code(below) which copy's and paste into a new ws but still paste zero's instead of values from the original ws. I'm not quite sure if the indirect and Iferror formulas in the original ws is causing this or my macro logic is somehow not right;

    Sub Annual_SummarySummary_Text()
    
    ' CopyPaste_P&Ls Macro
    
    Dim curWorkbook As Workbook
    Set curWorkbook = ActiveWorkbook
        
        application.ScreenUpdating = False
        Sheets("Annual Summary").Activate
        Sheets("Annual Summary").Copy
        Cells.Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues
        Sheets("Annual Summary").Select
        Cells.Select
        application.CutCopyMode = False
        Selection.Copy
    
        Selection.PasteSpecial Paste:=xlPasteValues
        application.CutCopyMode = False
        Sheets("Annual Summary").Select
     
        range("A6").Select
    
        application.ScreenUpdating = True
        
    curWorkbook.Activate
    Sheets("User Input&Pull").Activate
    range("H3").Select
        
    End Sub
    Once again my apologies for cross-posting. I value your time and assistance.

    Thanks Pi*

  9. #9
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    883

    Re: Paste Values vba error (MS Excel 2007)

    First of all just to be clear it isn't the cross-posting that is the issue per se, it is just that you didn't post a link to the cross-post.

    Anyway I will post the below as you seem to understand the issue above now and I posted a link to your cross-post in post #3 (as long as it is the only site you have cross-posted the question on)...

    Can you attach a anonymized copy of your workbook (see the excerpts in the quote below for how) as I can't reproduce your issue currently with how I think your workbook is set up.
    Dear Users,

    This message is to inform you that due to some technical issues the “Paper Clip" (To Attach Files) option that you see while posting new threads on Excel Forum is not operational right now. Our tech team is looking into the matter but as of now we would suggest you to kindly scroll down your Message box/Text Box a bit and then under the Additional Options tab, use the "Manage Attachments" option instead to attach your files with your queries while posting new threads......

    To upload a file from your computer, click the 'Browse' button and locate the file. To upload a file from another URL, enter the full URL for the file in the second box on this page. Once you have completed one of the boxes, click 'Upload'.

    Once the upload is completed the file name will appear below the input boxes in this window. You can then close the window to return to the new post screen

    Btw I think that both the codes below are doing the same as the last code you posted (post #8), can you check that I am right.

    Sub Annual_SummarySummary_Text3()
    
        ' CopyPaste_P&Ls Macro
    
        Dim curWorkbook As Workbook
        Set curWorkbook = ActiveWorkbook
    
        Application.ScreenUpdating = False
        Sheets("Annual Summary").Copy
        
        With ActiveSheet.Cells
            .Copy
            .PasteSpecial Paste:=xlPasteValues
        End With
         
        Application.CutCopyMode = False
        'Sheets("Annual Summary").Range("A6").Select
        'I don't see the purpose of the line above which is why I commented it out
        Application.ScreenUpdating = True
    
        Application.Goto curWorkbook.Sheets("User Input&Pull").Range("H3")
    
    End Sub
    Sub Annual_SummarySummary_Text2()
    
        ' CopyPaste_P&Ls Macro
    
        Dim curWorkbook As Workbook
        Set curWorkbook = ActiveWorkbook
    
        Application.ScreenUpdating = False
        Sheets("Annual Summary").Copy
    
        With ActiveSheet.Cells
            .Value = .Value
        End With
    
        'Sheets("Annual Summary").Range("A6").Select
        'I don't see the purpose of the line above which is why I commented it out
        Application.ScreenUpdating = True
    
        Application.Goto curWorkbook.Sheets("User Input&Pull").Range("H3")
    
    End Sub

  10. #10
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Paste Values vba error (MS Excel 2007)

    I'm guessing you're using formulas on your original Annual Summary sheet that break down when the sheet is copied as a new workbook. I can't be more specific without having more details. Try this code. It copies the values from the original sheet.

    Sub TextFile_Annual_Summary()
    ' TextedFile Macro
    ' Copy Annual Summary into new file and c/p value everything
    '
        
        Application.ScreenUpdating = False
        
        'Copy sheet as new workbook
        Sheets("Annual Summary").Copy
        
        'Rename copied sheet
        ActiveSheet.Name = ThisWorkbook.Sheets("Ref").Range("N10").Text & " Annual Summary"
        
        'Convert formulas to values and keep formats
        ActiveSheet.UsedRange.Value = ThisWorkbook.Sheets("Annual Summary").UsedRange.Value
        
        ActiveWindow.DisplayOutline = False
        Range("D7").Select
        
        Application.ScreenUpdating = True
        
    End Sub

  11. #11
    Forum Contributor
    Join Date
    03-17-2013
    Location
    USA, IL
    MS-Off Ver
    Excel 2010
    Posts
    121

    Re: Paste Values vba error (MS Excel 2007)

    Thank you all for the time and THANK YOU AlphaFrog for the assistance. Yours works perfectly.

    It seems the file I was using before was somehow corrupted so when I used the macro in last monts file it worked like a charm.

    Very much appreciated. I have learnt a few things these past few days and my flaws wont be repeated. Thanks again.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Disable Cut and Paste/Copy and Paste in Excel 2007
    By chessnsnuff in forum Excel General
    Replies: 2
    Last Post: 06-04-2013, 04:39 PM
  2. 2007 excel and 2007 word copy/paste
    By rkitson in forum Excel General
    Replies: 0
    Last Post: 02-19-2013, 02:34 PM
  3. [SOLVED] VBA Compile Error in Excel 2007 Only NOT 2007 Professional
    By SAsplin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-15-2013, 07:29 AM
  4. Replies: 3
    Last Post: 01-10-2013, 01:11 PM
  5. Replies: 1
    Last Post: 12-05-2012, 11:37 AM
  6. [SOLVED] Excel 2010: Run-time error at .Chart.Paste line within With statement (works on 2003/2007)
    By JohnMcCallum in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-04-2012, 11:53 AM
  7. Paste link from Excel 2007 to Word 2007 table
    By wmorton in forum Excel General
    Replies: 2
    Last Post: 06-19-2010, 06:49 PM
  8. Copy and paste from Excel 2007 to Word 2007
    By chuckied in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 04-01-2010, 08:20 PM

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