+ Reply to Thread
Results 1 to 9 of 9

Condense code

  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":

    Please Login or Register  to view this content.

    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.

  2. #2
    Valued Forum Contributor MaczaQ's Avatar
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    510

    Re: Condense code

    Maybe this way ?

    Please Login or Register  to view this content.
    Best Regards
    MaczaQ

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

    Re: Condense code

    Thanks for your suggestion MaczaQ, I wasn't quite sure how to implement it, but I used it with Case Select in the end:

    Please Login or Register  to view this content.
    What do you think?

  4. #4
    Valued Forum Contributor MaczaQ's Avatar
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    510

    Re: Condense code

    good solution but I only wonder why you always refer to one cell in sheet "Invoice"
    Please Login or Register  to view this content.
    When you will start your loop through all sheets at the end of loop you will get only one result in above mentioned cell.
    I suggest to change something for prevent to overwrite results ;-)

    Best Regards
    MaczaQ

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

    Re: Condense code

    There are 2 sheets copied to a new workbook each time the macro is run - "Invoice" and the backing data ("Completes", "Aborts" etc).

    Thanks again for your help.

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Condense code

    there's no need to select a sheet:

    Please Login or Register  to view this content.
    But this overwrites the same cell 7 times (?)



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

    Re: Condense code

    Even better snb, thanks for your suggestion.

    I'm using the following now (ADV sheets are a special case that need a bit extra info, and slightly amended formula to SUM):

    Please Login or Register  to view this content.
    -edit: The workbook will consist of 1 of the following 7 combinations of sheets:

    "Invoice" and "Completes"
    "Invoice" and "Aborts"
    "Invoice" and ...
    "Invoice" and ...
    "Invoice" and ...
    "Invoice" and ...
    "Invoice" and ...

    So the formula is only entered once on "Invoice" to sum the backing data.

    Again, many thanks both for your help.
    Last edited by tone640; 09-02-2011 at 06:58 AM. Reason: Clarifying, spelling

  8. #8
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Condense code

    Please Login or Register  to view this content.
    Last edited by snb; 09-02-2011 at 09:05 AM.

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

    Re: Condense code

    Thanks yet again, this has really helped my understanding.

+ 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