+ Reply to Thread
Results 1 to 5 of 5

VBA to perform sum of column values if number of rows and columns are not constant

  1. #1
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    882

    VBA to perform sum of column values if number of rows and columns are not constant

    Hi All

    The rows and columns are not constant in my example. So I want to perform the sum of all the columns using VBA. The number of rows and number of columns will always vary.

    Please seet attached SampleWB.

    Suppose total number of columns are stored in "ColCount" variable and total number of rows are stored in "RowCount" variable.

    so if I want to perform sum of all the values in each column then how can this be done?
    Please Login or Register  to view this content.
    Can anyone please help me to write For loop to perform sum of each column. Thanks
    Attached Files Attached Files

  2. #2
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: VBA to perform sum of column values if number of rows and columns are not constant

    You may try something like this....
    Please Login or Register  to view this content.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  3. #3
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: VBA to perform sum of column values if number of rows and columns are not constant

    Perhaps a macro like this?

    Please Login or Register  to view this content.
    Oops didn't check before posting so I did not see previous post!

    Alf
    Last edited by Alf; 02-17-2015 at 09:02 AM.

  4. #4
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    882

    Re: VBA to perform sum of column values if number of rows and columns are not constant

    Mant Thanks sktneer. It worked like a charm.

  5. #5
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: VBA to perform sum of column values if number of rows and columns are not constant

    You're welcome.

    If that takes care of your original question, please mark your thread as Solved by selecting Thread Tools (just above your first post) --> Mark thread as solved.

+ 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. Replies: 2
    Last Post: 10-09-2014, 06:14 PM
  2. [SOLVED] Macro for spreadsheets with different number of rows and a constant number of columns
    By MORACH in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 03-06-2014, 02:34 AM
  3. Replies: 2
    Last Post: 11-11-2008, 11:19 AM
  4. Replies: 2
    Last Post: 08-02-2006, 04:40 PM
  5. [SOLVED] Built-in Excel constant for maximum number of rows, for columns?
    By Howard Kaikow in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-07-2006, 10:20 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