+ Reply to Thread
Results 1 to 7 of 7

Summing values of a column

Hybrid View

  1. #1
    Registered User
    Join Date
    11-05-2007
    Posts
    34

    Summing values of a column

    Hi,

    I need to sum up the total value in each column to put into a value in another worksheet.

    I am using a for each loop to loop through each column,

    May I know how do I code it to sum the values from column D2 to last rowthat contains a value in that column.

    I need to do a sum for each row, I need to find the total of those values
    For example
    D2:D10
    E2:E15
    F2:F4



    Thanks

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    =SUM(D:D)-D1

    works for me.

    If VB is needed, the syntax would be

    Dim oneSum as Double
    
    oneSum = Application.Sum(Range("D:D"))-Val(Range("D1").Value)
    Last edited by mikerickson; 01-23-2008 at 12:45 AM.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Registered User
    Join Date
    11-05-2007
    Posts
    34
    Hi Mike,

    I am currently using code below

    For Each ce In ws.Range("D2:" & Cells(2, Columns.Count).End(xlToLeft).Address)
    
    total = Application.sum(Range("D:D")) - Val(Range("D1").Value)
    
    Next ce
    May I ask how do I apply the ce variable to substitute "D:D" and "D1"?
    The loop is to loop through each column and assuming that I will be have column E,F,G etc.. to sum up.

    Thanks

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    The spreadsheet formula

    =SUM(2:65586)-SUM(A:C)+SUM(A1:C1)

    will do that without looping.

    The VB would be
    Dim BigTotal As Double
    
    BigTotal = Application.Sum(Range("2:65536")) - Application.Sum(Range("A:C")) + Application.Sum(Range("A1:C1"))
    Last edited by mikerickson; 01-23-2008 at 01:07 AM.

  5. #5
    Registered User
    Join Date
    11-05-2007
    Posts
    34
    Hi Mike,
    I understand that your code sums up the total of the entire worksheet then minus the sum of column A and C, but it also adds value from Column D onwards.

    I need to find the sum of values in each column only.
    May I know how can I alter the codes to meet the criteria?

    Instead of summing D to IV etc..
    I need to sum up values in column D, then values in column E etc...

    Thanks

  6. #6
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    In post 2, that's how to get the sum of a column (except for row 1).

    The loop you posted is going from column D until the end and re-calculating Total for each column. What do you want done with these totals?

+ 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