+ Reply to Thread
Results 1 to 9 of 9

Cleaning up the code after recording a macro.

  1. #1
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Cleaning up the code after recording a macro.

    Hello everyone

    I wanted help cleaning up the code (see below) that was created by recording a macro. For instance declaring variables and so forth and something tighter with respect to the code.

    Also, I do not want the "Formulas" spreadsheet to update values upon opening ! It does not need to. I want to update values in the "Formulas" spreadsheet after pasting into it. I do not want to save the "Formulas" spreadsheet before closing it.

    Please Login or Register  to view this content.
    Last edited by AnthonyWB; 04-01-2010 at 02:30 PM.

  2. #2
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Re: Cleaning up the code after recording a macro.

    The following is an iimprovement. But I can not figure out the code to paste special values only. so instead I am using: .paste.

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Re: Cleaning up the code after recording a macro.

    I attempted the following improvement, and run into an error at Range("A1").Paste

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Re: Cleaning up the code after recording a macro.

    It seems I am following up by myself, but I am trying to leverage off of help, from other posts. I now have an error at the second "With ActiveSheet" at the .Paste. Any help would be appreciated.

    Please Login or Register  to view this content.

  5. #5
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Cleaning up the code after recording a macro.

    Try this

    Please Login or Register  to view this content.

    This defines each workbook,sheet and range used. Hopefully!

    Note the method of copying, if nothing else.

    Hope I didn't get in a tangle with this I was trying to keep up with your Posts!
    Last edited by Marcol; 03-31-2010 at 07:02 PM. Reason: Typos

  6. #6
    Forum Expert
    Join Date
    09-09-2005
    Location
    England
    MS-Off Ver
    2007
    Posts
    1,500

    Re: Cleaning up the code after recording a macro.

    Whilst the code above mat supercede your question
    Application.CutCopyMode = False stops the copy above it being remembered, so when it comes to paste later, there is nothing to paste

    Regards

    Dav

  7. #7
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Re: Cleaning up the code after recording a macro.

    Your code did not run. It looks very professional however. Thanks. Perhaps it's best to start over. Here it is:

    1. We are copying a range [A1:Z50000] from the "105_12_31_2009" worksheet in the 105_Report_Spreadsheet workbook.

    2. And then pasting it onto a range [A1:Z50000] onto the "Formulas" worksheet in the Formulas workbook. We then update the formulas on the "Formulas" worksheet. Copy the entire worksheet.

    3. We then create a new workbook = 105_Report_Spreadsheet_Values and rename sheet1 to 105_12_31_2009_values, and paste special values onto that sheet.

    4.We then "go back" and clear the contents which was pasted onto the Formulas worksheet in the Formulas workbook.

    5. Save all files and close them.

    I appreciate all the help. There is a method to this madness.

  8. #8
    Forum Expert
    Join Date
    09-09-2005
    Location
    England
    MS-Off Ver
    2007
    Posts
    1,500

    Re: Cleaning up the code after recording a macro.

    if it is only the pastespecial bit that is defeating you, you can record the code through a keystroke macros

    it is something like

    Please Login or Register  to view this content.
    Regards

    Dav

  9. #9
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Re: Cleaning up the code after recording a macro.

    I figured out a way. It's incredibly ugly...but it works. Thanks for all the help.

    Please Login or Register  to view this content.

+ 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