+ Reply to Thread
Results 1 to 11 of 11

If the values in column a are duplicate, sum the corresponding values in column B

  1. #1
    Registered User
    Join Date
    10-04-2017
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    8

    If the values in column a are duplicate, sum the corresponding values in column B

    Hello VBA Gods, an amateur is need of help.

    I have values in column A representing IDs and values in column B representing amounts purchased by those IDs. I now need to write a sub that finds the total amount spent by each customer on the list and reports those whose total is more than $800 on a new worksheet.

    I have written a code that works to sort the data according to ID number to make this problem easier. I know I will have to use a Loop, but am confused as to how I should proceed to write the sub.

    Thanks in advance!

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: If the values in column a are duplicate, sum the corresponding values in column B

    Hi VBAmateur and welcome to the forum,

    Why do you need VBA? If you do a pivot table of your data and sum the values it will be much easier.

    See the attached to give my answer.

    Why VBA when Pivot gives answer.xlsx
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    10-04-2017
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    8
    I know how to do this with pivot tables, but the question specifically asks to use VBA

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: If the values in column a are duplicate, sum the corresponding values in column B

    Assuming Herder in 1st row, data starts from A2
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-04-2017
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    8

    Re: If the values in column a are duplicate, sum the corresponding values in column B

    Thanks Jindon! But do you know of any other ways to get this to work without using the scripting dictionary? This is not something I have learned yet. Thanks again!

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: If the values in column a are duplicate, sum the corresponding values in column B

    What did you learn then?

  7. #7
    Registered User
    Join Date
    10-04-2017
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    8

    Re: If the values in column a are duplicate, sum the corresponding values in column B

    So far I have learned the basics like arrays, loops, using Excels functions in vba. Its the basics. I thought this problem might be solvable using the basics and a few types of loops like for each, do until, do while.
    Thanks again for the quick responses

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: If the values in column a are duplicate, sum the corresponding values in column B

    Basic excel functionality only.
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    10-04-2017
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    8

    Re: If the values in column a are duplicate, sum the corresponding values in column B

    Thank you! This makes a lot more sense to me. I was wonderinf if there was anyway to use the do until loop in this problem, as that is what i was thinking of using first. Something that would sum the purchases $ cells until the A column cells did not equal each other, and then i would loop to the next ID in column A somehow? So i would have to use For Each in the code as well?
    Sorry for all the questions, just trying to see if my thought process was somewhat correct.

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: If the values in column a are duplicate, sum the corresponding values in column B

    If you think so, just write a code for yourself first and ask where you stuck.

  11. #11
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: If the values in column a are duplicate, sum the corresponding values in column B

    Hi vbamatuer,

    The reason for Pivot Tables or Scripting Dictionary is to combine the ID's. The first step is to get a unique ID list. In jindon's second example he used a "RemoveDuplicates" tool built into Excel. Excel has lots of WorksheetFunctions that can be used in VBA, that compliment the power of VBA to get answers. I'd still go back to using a Pivot Table for getting your final answer, but it seems you want to learn VBA, without learning Excel Functions instead.

    Read more about worksheetfunction at:
    https://msdn.microsoft.com/en-us/lib...ffice.14).aspx

+ 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. [SOLVED] Putting a zero in column B for duplicate values and 1 for unique values
    By treeantz in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-17-2016, 12:37 AM
  2. detecting duplicate values in a column (values are made of formula)
    By louiemangaring in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-12-2015, 06:25 AM
  3. Replies: 1
    Last Post: 01-23-2014, 11:18 PM
  4. Replies: 7
    Last Post: 12-07-2013, 02:33 PM
  5. [SOLVED] Need to Merege Duplicate Row Values With Varying Column Values into one Row
    By LoveUsingExcel in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 11-01-2013, 12:26 PM
  6. Create a row (or column) of non-duplicate values from a column containing duplicate values
    By 777volkov777 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-17-2013, 11:11 AM
  7. [SOLVED] Need Urgent help on Adjacent values of Duplicate column values should be be in single row.
    By anto_01 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-11-2012, 09:55 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