+ Reply to Thread
Results 1 to 9 of 9

Macro to sum a dynamic/variable range - I'm making this harder than it has to be, I think.

  1. #1
    Registered User
    Join Date
    01-16-2009
    Location
    Hartford, CT
    MS-Off Ver
    Excel 2010
    Posts
    56

    Macro to sum a dynamic/variable range - I'm making this harder than it has to be, I think.

    I have a workbook consisting of several sheets. Each week, the data is cleared from every sheet and replaced with new data (via a macro). The new data will have the same structure (data starts in the same row, same number of columns) every week. However, the number of rows can vary - and sometimes there is only one row of data. I currently have a macro that sums every column of every sheet - but it falters in the case where these is only one row of data to sum (there needs to be a blank row between the data and the sum).

    What is the simplest way to accomplish this seamlessly? I know the code to run the operation on multiple sheets, so no need to go into that.

    See attachment to really understand what I'm getting at (and how easy it seems it ought to be)
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    02-07-2012
    Location
    MIA
    MS-Off Ver
    Excel 2007, 2010
    Posts
    429

    Re: Macro to sum a dynamic/variable range - I'm making this harder than it has to be, I th

    Will the data always start on row 8?
    .?*??)
    `?.???.?*??)?.?*?)
    (?.?? (?.?
    Pichingualas <---
    ??????????????????????????

    Wrap your code with CODE TAGS.
    Thank those who helped you, Don't forget to add to their REPUTATION!!! (click on the star below their post).
    Please mark your threads as [SOLVED] when they are (Thread Tools->Mark thread as Solved).

  3. #3
    Registered User
    Join Date
    01-16-2009
    Location
    Hartford, CT
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Macro to sum a dynamic/variable range - I'm making this harder than it has to be, I th

    Indeed it will.

  4. #4
    Forum Contributor
    Join Date
    02-07-2012
    Location
    MIA
    MS-Off Ver
    Excel 2007, 2010
    Posts
    429

    Re: Macro to sum a dynamic/variable range - I'm making this harder than it has to be, I th

    This should do what you need:

    Please Login or Register  to view this content.
    Last edited by Pichingualas; 08-07-2012 at 10:58 AM.

  5. #5
    Forum Contributor
    Join Date
    02-07-2012
    Location
    MIA
    MS-Off Ver
    Excel 2007, 2010
    Posts
    429

    Re: Macro to sum a dynamic/variable range - I'm making this harder than it has to be, I th

    I did a little change on the code, but it's still basically the same thing.

  6. #6
    Registered User
    Join Date
    01-16-2009
    Location
    Hartford, CT
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Macro to sum a dynamic/variable range - I'm making this harder than it has to be, I th

    ALMOST perfect - it's not skipping a row before inserting the sum of the columns. I made the change that I thought was necessary, but it crashed Excel, so I think I didn't change the correct thing. Can you modify?

  7. #7
    Forum Contributor
    Join Date
    02-07-2012
    Location
    MIA
    MS-Off Ver
    Excel 2007, 2010
    Posts
    429

    Re: Macro to sum a dynamic/variable range - I'm making this harder than it has to be, I th

    Oh sorry I thought you wanted not to skip a row lol. Give me a minute.

    ---------- Post added at 12:27 PM ---------- Previous post was at 12:23 PM ----------

    Just a small change then:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    01-16-2009
    Location
    Hartford, CT
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Macro to sum a dynamic/variable range - I'm making this harder than it has to be, I th

    Dang! That's the change I made, but Excel then crashed on me. I guess it was just coincidence. Thanks so much!!

  9. #9
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Macro to sum a dynamic/variable range - I'm making this harder than it has to be, I th

    @ ajava

    Based on your last post it seems that you are satisfied with the solution(s) you've received but you haven't marked your thread as SOLVED. I'll do that for you now but please keep in mind for your future threads that Rule #9 requires you to do that yourself. If your problem has not been solved you can use Thread Tools (located above your first post) and choose "Mark this thread as unsolved".
    Thanks.

+ 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