+ Reply to Thread
Results 1 to 8 of 8

Group / Sum two columns

  1. #1
    Forum Contributor
    Join Date
    03-20-2013
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    200

    Group / Sum two columns

    Hi

    quite difficult to explain in the subject, but this is what im after

    i have two columns, A and B on sheet1

    Column A Column B
    1 22.30
    1 13.40
    1 55.20
    3 8.69
    3 6.58
    4 5.55
    4 12.55
    4 33.55

    what i would like is some vba to convert the above, onto sheet2 as follows

    Column A Column B
    1 90.90 (so a sum of all the values relating to 1 in column A)
    3 15.27
    4 46.10


    the range on sheet 1, could go up to row A1:B1000

    many thanks in advance

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,463

    Re: Group / Sum two columns

    Why use VBA? You can do it quite easily using a SUMIF formula in B1 of Sheet2, like this:

    =SUMIF(Sheet1!A:A,A1,Sheet1!B:B)

    then copy down.

    Hope this helps.

    Pete

  3. #3
    Forum Contributor
    Join Date
    03-20-2013
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    200

    Re: Group / Sum two columns

    Hi Pete, thanks for the reply

    the requestor, has requested that they simply press a button, and sheet2 is created, with the variable range etc. is it possible to put your method into vba with the same end result? thanks!

  4. #4
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Group / Sum two columns

    You can try this:
    Please Login or Register  to view this content.
    Amended slightly from a previous code
    多么想要告诉你 我好喜欢你

  5. #5
    Forum Contributor
    Join Date
    03-20-2013
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    200

    Re: Group / Sum two columns

    i get a invalid bracketing error message on this line

    rs.Open s, cn


    thank you

  6. #6
    Forum Contributor
    Join Date
    03-20-2013
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    200

    Re: Group / Sum two columns

    i get a invalid bracketing error message on this line

    rs.Open s, cn

    i changed the brackets to ( from [ and, then the sheet it creates only sums the first number from column a

    thank you

  7. #7
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Group / Sum two columns

    How does your data structure looks like? There are blanks inbetween rows? Post a sample workbook with de-sensitized data if possible.

  8. #8
    Forum Contributor
    Join Date
    03-20-2013
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    200

    Re: Group / Sum two columns

    Hi

    i managed to solve it, but copying column A into sheet 2, removing duplicates, then applying the sum if,,
    thanks anyway, TA

+ 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] Group/Un-group Columns through buttons using VBA
    By KamranMustafa in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-11-2016, 04:23 AM
  2. Replies: 1
    Last Post: 02-03-2016, 06:43 PM
  3. Group many columns by row
    By Kyle5325235 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-13-2015, 01:32 AM
  4. Replies: 1
    Last Post: 02-10-2014, 10:26 PM
  5. Replies: 2
    Last Post: 01-18-2013, 12:45 PM
  6. Sorting groups of columns to a related group of columns
    By fuadramsey in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-15-2007, 07:56 PM
  7. [SOLVED] to convert columns to rows having mulit independent group columns
    By Quacy in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-22-2006, 06:25 PM

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