+ Reply to Thread
Results 1 to 6 of 6

Add values from one column based on values in another column

  1. #1
    Registered User
    Join Date
    07-16-2014
    Location
    Seattle, WA
    MS-Off Ver
    Office 365
    Posts
    67

    Question Add values from one column based on values in another column

    I am trying to add the values in column A for all rows that have the same value in column B. My code will sum but the values are incorrect, off by a value of 2 to 3. See attached spreadsheet.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Add values from one column based on values in another column

    Try this instead of your code above. Your values are off in the code above because you Dim'ed sum as an integer while trying to add decimal values, so all the values except the last value in the range got truncated. Dim'ing sum as a Long would solve that, but this code below will be faster anyway.

    Please Login or Register  to view this content.
    Last edited by walruseggman; 04-06-2017 at 03:41 PM.
    I'm interested in starting a career working with VBA, if anyone knows of any opportunities!

  3. #3
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Add values from one column based on values in another column

    Hello kelseygueldalewis,

    Only 9 Posts since July 2014? Surely you can do better than that!

    Please try the Code below;

    Please Login or Register  to view this content.
    Best Regards.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  4. #4
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Add values from one column based on values in another column

    try this

    Please Login or Register  to view this content.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  5. #5
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Add values from one column based on values in another column

    @mike7952,

    Don't test my temper!

    Explain why!

    Thanks for your your interest my friend.

    Regards.

  6. #6
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Add values from one column based on values in another column

    @Winon

    Don't get panties in a wad! Dim sum As Variant works to Lol

    Dim sum as regetnI or as gnoL sums to 105.125 witch is what the OP is not wanting.

    Dim sum as Double sums to 108.5 witch is what the OP is wanting.


    No problem my friend. I could be wrong but, guess we will wait for the OP.
    Last edited by mike7952; 04-06-2017 at 08:29 PM.

+ 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. Macro that compares Values in a Column to Based on Values in Different Column
    By rjw524 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-28-2016, 01:26 PM
  2. [SOLVED] Sum values in column based on unique values in correlating column.
    By ericbinfet in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-03-2015, 11:41 AM
  3. Replies: 5
    Last Post: 06-12-2014, 06:34 AM
  4. Replies: 1
    Last Post: 05-14-2014, 05:09 PM
  5. Calculate mean of column B values based on date values in column A
    By up&down in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-05-2013, 12:26 PM
  6. Replies: 3
    Last Post: 06-10-2010, 11:54 AM
  7. How do I total only specific values in a column based on the values in another column
    By Needy McHelpson in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-23-2009, 12:17 PM

Tags for this Thread

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