Results 1 to 9 of 9

Condense code

Threaded View

  1. #1
    Forum Contributor
    Join Date
    06-15-2011
    Location
    Chester, England
    MS-Off Ver
    Excel 2013
    Posts
    117

    Condense code

    I am currently learning to condense code by turning several macros that are similar into one that I can use for all.

    The below is the last bit that I need to change to have a single macro instead of 7.

    At this point, I am copying the ActiveSheet and a sheet called "Invoice" to a new workbook, then adding the formula to the sheet called "Invoice":

    Sub InvComps()
    
        Sheets(Array("Invoice", ActiveSheet.Name)).Copy
        Range("J22").FormulaR1C1 = "=SUM(Complete!C[17])"
        
    End Sub
    
    Sub InvAborts()
    
        Sheets(Array("Invoice", ActiveSheet.Name)).Copy
        Range("J22").FormulaR1C1 = "=SUM(Aborts!C[17])"
        
    End Sub
    
    Sub InvEmergs()
    
        Sheets(Array("Invoice", ActiveSheet.Name)).Copy
        Range("J22").FormulaR1C1 = "=SUM(Emergencies!C[17])"
    
    End Sub
    
    Sub InvADV()
    
        Sheets(Array("Invoice", ActiveSheet.Name)).Copy
        Range("J22").FormulaR1C1 = "=SUM(ADV!C[17])"
    
    End Sub
    
    Sub InvSSE()
    
        Sheets(Array("Invoice", ActiveSheet.Name)).Copy
        Range("J22").FormulaR1C1 = "=SUM(SSE!C[17])"
    
    End Sub
    
    Sub InvUKMA()
    
        Sheets(Array("Invoice", ActiveSheet.Name)).Copy
        Range("J22").FormulaR1C1 = "=SUM(UKMA!C[17])"
    
    End Sub
    
    Sub InvUKGC()
    
        Sheets(Array("Invoice", ActiveSheet.Name)).Copy
        Range("J22").FormulaR1C1 = "=SUM(UKGC!C[17])"
    
    End Sub

    How do I get the sheet name in each formula to change each time so that it refers to the sheet in the workbook that isn't "Invoice"?

    Thanks in advance.
    Last edited by tone640; 09-01-2011 at 11:00 AM.

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