+ Reply to Thread
Results 1 to 10 of 10

VBA code to sum up values in column B depending on column A

  1. #1
    Forum Contributor
    Join Date
    02-14-2008
    Location
    Manchester, England
    MS-Off Ver
    2007
    Posts
    110

    VBA code to sum up values in column B depending on column A

    I'm hoping someone can help me write some code.

    What I want to do is sum up the values in column B depending on the category in column A. Let me give an example of what my spreadsheet looks like

    A--------B

    HOLSA--50
    HOLSB-- 25
    HOLSC---20
    SICKA---10
    SICKB ---10

    In column C I'd look to group these up by the first 4 letters so it just says HOLS 95 and SICK 20.

    There's quite a few of these and they will change but they will always be grouped by the first 4 letters as they will always be the same for each category so I'm guessing I'll somehow need to use a wild card.

    Is anyone able to point me in the right direction with this.

    Thanks

  2. #2
    Registered User
    Join Date
    11-29-2010
    Location
    Belgium
    MS-Off Ver
    2010
    Posts
    87

    Re: VBA code to sum up values in column B depending on column A

    Hi,

    There's no need to write a VBA code for this. Put the following formula in the correct row in column C and copy it down till the last row.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Make sure to adjust A1 and B1 to the correct row number.

    Greetz,
    Tino XXL

  3. #3
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: VBA code to sum up values in column B depending on column A

    Here is non-vba solution
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    02-14-2008
    Location
    Manchester, England
    MS-Off Ver
    2007
    Posts
    110

    Re: VBA code to sum up values in column B depending on column A

    I was going to write it in VBA so someone who can't use Excel can just push a button. I guess I can just record a macro that applies this formula to the relevant cells

  5. #5
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: VBA code to sum up values in column B depending on column A

    dan27, with my solution he doesn't need to push button. It will automatically provide solution. Just enter new values

  6. #6
    Forum Contributor
    Join Date
    02-14-2008
    Location
    Manchester, England
    MS-Off Ver
    2007
    Posts
    110

    Re: VBA code to sum up values in column B depending on column A

    This is good but it misses out occasions where 0 is the value and only returns the first 4 letters of column A. Ideally I'd like the ouput to be set format.

    i.e

    Holidays 95
    Sickness 20

    And so on

    Thanks kindly for your help

  7. #7
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: VBA code to sum up values in column B depending on column A

    Can you upload example workbook with your inputs and desired output?

  8. #8
    Forum Contributor
    Join Date
    02-14-2008
    Location
    Manchester, England
    MS-Off Ver
    2007
    Posts
    110

    Re: VBA code to sum up values in column B depending on column A

    Sure. Columns A and B are a copy and paste from my pivot table. Columns G&H are desired results.

    Thanks again for your help.
    Attached Files Attached Files

  9. #9
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: VBA code to sum up values in column B depending on column A

    I think you need to define new table that will compare your names (don't worry, you would need to define those too if you creating VBA because I don't see logic to extract this out).
    Attached Files Attached Files

  10. #10
    Forum Contributor
    Join Date
    02-14-2008
    Location
    Manchester, England
    MS-Off Ver
    2007
    Posts
    110

    Re: VBA code to sum up values in column B depending on column A

    I am happy to define them in VBA. I just see this now become complex and leaves too much room for error for someone who doesn't know what they're doing.
    If you're able to write in VBA then I can do all the defining if you can just do me a template.

    Thanks

+ 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