+ Reply to Thread
Results 1 to 3 of 3

Can this code be shortened?

  1. #1
    Forum Contributor
    Join Date
    06-25-2013
    Location
    Longview, TX
    MS-Off Ver
    MS365
    Posts
    338

    Can this code be shortened?

    I've got this really long macro that does exactly what I want, but a large chunk of the code at the end seems repetitive to me. But it was the only way I could figure to do what I need. I'm just wondering if some of it could be consolidated.
    I'll attach my practice workbook with a sheet before the macro runs at all, a second sheet where I've only run the macro to just before the repetitive part and a third sheet showing after the whole macro runs.
    Basically, what I have it doing is adding a total at the end of each section in "Account Activity Details", then adding a formula in H & I of the "Grand Total" row to sum up all of the section totals. Then, just below that, it adds a formula in I to sum up those totals. I had to designate the start of each section, then refer to the cells before or after them to tell it where to put the section totals. I can't refer to specific row numbers, because, naturally, the reports are different lengths each month.
    If this is already a good way to do it, then I'm fine with that, but if there's something more efficient, that'd be good too.
    Below is that part of the code:
    Please Login or Register  to view this content.
    Thanks!

    Jenny
    Attached Files Attached Files

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Can this code be shortened?

    While you can write more sophisticated code, in the end, it all comes down to whether you can understand it. If you compact this code, the come back to it a year later for modification, are you going to be able to understand it? A lot can be said for K.I.S.S.

    [gets down off soapbox]

    So, my suggestion is only to do away with all the Withs.

    Please Login or Register  to view this content.
    Oh, and I'd add a comment for each one of these, just to spell it out.
    David
    (*) Reputation points appreciated.

  3. #3
    Forum Contributor
    Join Date
    06-25-2013
    Location
    Longview, TX
    MS-Off Ver
    MS365
    Posts
    338

    Re: Can this code be shortened?

    Quote Originally Posted by Tinbendr View Post
    While you can write more sophisticated code, in the end, it all comes down to whether you can understand it. If you compact this code, the come back to it a year later for modification, are you going to be able to understand it? A lot can be said for K.I.S.S.

    [gets down off soapbox]

    So, my suggestion is only to do away with all the Withs.

    Please Login or Register  to view this content.
    Oh, and I'd add a comment for each one of these, just to spell it out.
    LOL - yeah, that's true! Although I'd probably have no trouble figuring it out, somebody else might be looking at it for some reason & have no clue what's going on.

    I thought I needed the Withs; glad to be able to remove them! It looks MUCH better without those. Thanks!

    Jenny

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Can this formula be shortened ?
    By Fantaxia in forum Excel General
    Replies: 12
    Last Post: 04-05-2014, 06:21 AM
  2. Can this formula be shortened?
    By zookeepertx in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-04-2014, 02:54 PM
  3. [SOLVED] Shortened IF Formula
    By DeamonX in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-23-2013, 06:21 AM
  4. Can this formula be shortened?
    By nandomer in forum Excel General
    Replies: 3
    Last Post: 12-01-2011, 05:05 PM
  5. Can this Formula be shortened
    By IsoTech in forum Excel General
    Replies: 6
    Last Post: 08-04-2010, 04:04 AM

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