+ Reply to Thread
Results 1 to 16 of 16

Loop through and sum columns

  1. #1
    Forum Contributor
    Join Date
    05-09-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    259

    Loop through and sum columns

    Okay so I'm nearly there with this code, it works on the first worksheet but when it selects the remaining ones it is not summing column c!!!! any ideas??

    Please Login or Register  to view this content.

  2. #2
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Loop through and sum columns

    Try this:-
    Please Login or Register  to view this content.
    Regards Mick

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,420

    Re: Loop through and sum columns

    Possibly data related. This is a bit shorter and assumes that all columns have the same number of rows determined by column C:

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,420

    Re: Loop through and sum columns

    @Mick

    I think this:

    Please Login or Register  to view this content.

    should be this:

    Please Login or Register  to view this content.

    Regards, TMS

  5. #5
    Forum Contributor
    Join Date
    05-09-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    259

    Re: Loop through and sum columns

    Mickg, this still does the same as mine! Maybe its me?

  6. #6
    Forum Contributor
    Join Date
    05-09-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    259

    Re: Loop through and sum columns

    Tmshucks will try your new code, the other one you posted would not work as varying row sizes in worksheets, appreciate all the advice though guys as I'm new to this, thanks

  7. #7
    Forum Contributor
    Join Date
    05-09-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    259

    Re: Loop through and sum columns

    TMs, where should I put this, sorry for being dozy!

  8. #8
    Forum Contributor
    Join Date
    05-09-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    259

    Re: Loop through and sum columns

    Please Login or Register  to view this content.

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,420

    Re: Loop through and sum columns

    It's not an amendment to my code, it is an amendment to Mick's code which doesn't make the same assumption that mine did.

    However, you do need to qualify the Rows.Count and relate it to the wksht. Hence "Rows.Count" becomes ".Rows.Count"


    Regards, TMS

  10. #10
    Forum Contributor
    Join Date
    05-09-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    259

    Re: Loop through and sum columns

    Ah,okay thanks I will try it

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,420

    Re: Loop through and sum columns

    No problem. As I said, it's possibly data related so you may want to post a sample workbook.


    Regards, TMS

  12. #12
    Forum Contributor
    Join Date
    05-09-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    259

    Smile Re: Loop through and sum columns

    Hi, yes I can but I'm now doing this from my phone as i'm out. Anychance I could post tomorrow and if your browsing you could look? or I could pm you? thanks for the advice you have given appreciate it

  13. #13
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Loop through and sum columns

    Not sure where you are on this , but the loop should have said 3 to 10 not 3 to 8.
    In worked for me.
    Last edited by MickG; 05-17-2013 at 01:42 PM.

  14. #14
    Forum Contributor
    Join Date
    05-09-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    259

    Re: Loop through and sum columns

    Okay thank you, I will try this tomorrow as i'm out at the mo and doing this from my phone. Thanks for your suggestions and advice .

  15. #15
    Forum Contributor
    Join Date
    05-09-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    259

    Re: Loop through and sum columns

    MickG invalid reference is what I get when I run the code, its on the
    Please Login or Register  to view this content.
    part? any ideas?

  16. #16
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,420

    Re: Loop through and sum columns

    Which line of code is that?

    There is no reference to just ".Rows". It is, in the original, "Rows.Count" and, in my revision, ".Rows.Count"

    Regards, TMS

+ 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