+ Reply to Thread
Results 1 to 17 of 17

Error when executing VBA code to remove all formulas from Workbook

  1. #1
    Forum Contributor
    Join Date
    07-30-2012
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    139

    Error when executing VBA code to remove all formulas from Workbook

    I am developing a close procedure for some data entry forms. The procedure needs to do 3 things:

    1 - Convert all formulas to call values

    2 - Save the file in a predetermined location / file name

    3 - Exit excel

    I had successfully created code that would do numbers 2 and 3, but when I tried to add code to address number one I (shown in bold below) started getting a run time error:

    Run-Time error '1004':

    PasteSpecial method of range class failed
    This is the code as i have it so far:

    Please Login or Register  to view this content.
    Does anyone have any idea what I might be doing wrong?

    Thanks in advance

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Error when executing VBA code to remove all formulas from Workbook

    Please Login or Register  to view this content.
    Where are you pasting the selection?

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Error when executing VBA code to remove all formulas from Workbook

    Try this for pasting values.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  4. #4
    Forum Contributor
    Join Date
    07-30-2012
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: Error when executing VBA code to remove all formulas from Workbook

    @Norie, thank you very much, I'll play with this

    @AB33 - I wanted to have it pasted over the back over itself so that all cells are the same as they were before but with values instead of formulas.

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Error when executing VBA code to remove all formulas from Workbook

    What I meant was you have not selected(Specified) in which cell you want to post the selected copy cells
    In Norie's case, the selected cell is .Cells(1,1) -that where the selected copy will pasted in to.

  6. #6
    Forum Contributor
    Join Date
    07-30-2012
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: Error when executing VBA code to remove all formulas from Workbook

    aaah, I see. Thank you AB33

  7. #7
    Forum Contributor
    Join Date
    07-30-2012
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: Error when executing VBA code to remove all formulas from Workbook

    I seem to be struggling with this still.

    I modified my code to add the cell reference and now I'm getting another error (I must have messed up the syntax?):

    Please Login or Register  to view this content.
    Compile error:

    Invalid or unqualified reference

    I also tried using Nories code snippet but I'm getting a similar error with that one:


    Please Login or Register  to view this content.
    Run-Time error '1004':
    PasteSpecial method of Range class failed

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Error when executing VBA code to remove all formulas from Workbook

    Are there any protected sheets in the workbook?

    Any sheets with charts/buttons/shapes?

  9. #9
    Forum Contributor
    Join Date
    07-30-2012
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: Error when executing VBA code to remove all formulas from Workbook

    No sheets are protected, however there is a sheet with a text box that I'm using as a button to run the close procedure.

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Error when executing VBA code to remove all formulas from Workbook

    Do you want to copy/paste that worksheet?

  11. #11
    Forum Contributor
    Join Date
    05-05-2009
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010 and 365
    Posts
    113

    Re: Error when executing VBA code to remove all formulas from Workbook

    Unqualified reference = leading dot not within with statement.

    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    07-30-2012
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: Error when executing VBA code to remove all formulas from Workbook

    It doesn't need to be. It would actually be better if it wasn't.

  13. #13
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Error when executing VBA code to remove all formulas from Workbook

    You can exclude that sheet, or any other, like this.
    Please Login or Register  to view this content.

  14. #14
    Forum Contributor
    Join Date
    07-30-2012
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: Error when executing VBA code to remove all formulas from Workbook

    Brilliant, Thank you all for your help

  15. #15
    Forum Contributor
    Join Date
    05-05-2009
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010 and 365
    Posts
    113

    Re: Error when executing VBA code to remove all formulas from Workbook

    Quote Originally Posted by brharrii View Post
    It doesn't need to be. It would actually be better if it wasn't.
    I was just pointing out what was causing the compile error. It seems there were other issues as well but the unqualified reference was caused by the leading period with no reference object.

  16. #16
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Error when executing VBA code to remove all formulas from Workbook

    Cyclops

    I think the OP was replying to my question about copying/pasting the worksheet with the button.

  17. #17
    Forum Contributor
    Join Date
    07-30-2012
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: Error when executing VBA code to remove all formulas from Workbook

    You were right cyclops, I was responding to one of the other posters. Your comment helped me find one of the issues in the code, Thank you very much


    I also gave "reputation" to everyone who helped me resolve this issue. Thank you all for your assistance

+ 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