Results 1 to 9 of 9

Cleaning up the code after recording a macro.

Threaded View

  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.

    Option Explicit
    
    Sub Macro3()
    '
    ' Macro3 Macro
    '
    
    '
        Workbooks.Open Filename:= _
            "L:\157 Test Files for Automation\105_Report_Spreadsheet.xlsm"
            Range("A1:Z50000").Select
            Selection.Copy
        
        Workbooks.Open Filename:="L:\157 Test Files for Automation\Formulas.xlsm", _
            UpdateLinks:=3
            Range("A1").Select
            ActiveSheet.Paste
            Range("A1:AV50000").Select
            Application.CutCopyMode = False
            Selection.Copy
        
        Workbooks.Add
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Range("A1:AV50000").Select
        Selection.NumberFormat = "#,##0.00_);[Red](#,##0.00)"
        Sheets("Sheet1").Select
        Sheets("Sheet1").Name = "12_31_2009"
        Range("A1").Select
        Application.CutCopyMode = False
        ActiveWorkbook.SaveAs Filename:= _
            "L:\157 Test Files for Automation\105_Report_Values.xlsm", FileFormat:= _
            xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
        ActiveWindow.Close
    
        Range("A1:Z50000").Select
        Selection.ClearContents
        ActiveWorkbook.Close
        ActiveWindow.Close
    End Sub
    Last edited by AnthonyWB; 04-01-2010 at 02:30 PM.

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