+ Reply to Thread
Results 1 to 11 of 11

Annoying Macro - Sorting Cells and Summing Totals

  1. #1
    Registered User
    Join Date
    07-08-2013
    Location
    Fort Wayne, IN
    MS-Off Ver
    Excel 2010
    Posts
    61

    Annoying Macro - Sorting Cells and Summing Totals

    BUYSHEET TEST.xlsm
    EDIT: Use this sample workbook to see what I would like the final product to look like




    I have an extremely annoying macro that I am trying to fix (it was written in 2001).

    What happens is that it organizes the rows by alphabetical order (according to the value in column A). For example: all "Bolts" will be grouped and their associated costs with them. Below that will be 'Nuts' and below that 'Washers'.
    Then it is supposed to insert a row and sum the total of that item. For example: 8 rows of bolts with their item costs a row of the total costs of those rows, then 4 rows of nuts with their item costs and a rows of the total....... so on and so forth.

    The code that was written uses the following syntax and I believe there has to be a much easier way (with a lot less selecting) to write it.
    This also hasn't worked flawlessly. There are several times that the sum formulas don't grab all of the values needed and also sometimes grabb too many values (the rows of the other items).

    I know the macro is lengthy but it is repetitive so there has to be a better way. Any ideas?
    Last edited by ahilty; 07-12-2013 at 01:24 PM.

  2. #2
    Registered User
    Join Date
    07-08-2013
    Location
    Fort Wayne, IN
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: Annoying Macro - Sorting Cells and Summing Totals

    I have attached a test workbook with values entered and the macro as is attached.

    You can see it doesn't sort all of the bolts into one group nor all or the nuts or washers.

    BUYSHEET TEST.xlsm

    I know this is a lot of work, so thank you to anyone giving it a try.

  3. #3
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,052

    Re: Annoying Macro - Sorting Cells and Summing Totals

    The following assumes that row 1 has the column headers: "Item" in A1 and "Quantity" in B1. It will sort according to "Item" and give you the subtotals and grand total for "Quantity". You may have to change the headers and sheet name to suit your needs.
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    07-08-2013
    Location
    Fort Wayne, IN
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: Annoying Macro - Sorting Cells and Summing Totals

    Mumps,
    This might work for the sorting (I'm trying it now). Please see the attached file to see the full annoyance.

  5. #5
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,052

    Re: Annoying Macro - Sorting Cells and Summing Totals

    Try the attached file. I've had to remove a few rows at the top to make the subtotals work. I hope that's OK. Just click the "Sort and Subtotal" button.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    07-08-2013
    Location
    Fort Wayne, IN
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: Annoying Macro - Sorting Cells and Summing Totals

    Mumps,
    I like what you did there - I will be inputting this into my code and apply the sum to all fields and see how it goes after I get back from lunch.
    Thank you for the help, I'll let you know how it turns out. You've been more than helpful.

  7. #7
    Registered User
    Join Date
    07-08-2013
    Location
    Fort Wayne, IN
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: Annoying Macro - Sorting Cells and Summing Totals

    Mumps and others,

    I used the above suggested code and I seem to be running into some problems when trying to insert it into what I have.

    The rows you deleted to make the header obvious cannot be deleted. Also, the fields that need subtotals under them are the following fields:
    (1)Labor Total, (2)Material Total, (3)Sub Total, (4) Owned Equip Total, and (5)Rent Equip Total.

    You have reduced the annoy repetition and shortened the code by a mile but it isn't quite doing everything it needs to.
    Any other ideas?

    PS. The test file is attached above if anyone else would like to try and help.

  8. #8
    Registered User
    Join Date
    07-08-2013
    Location
    Fort Wayne, IN
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: Annoying Macro - Sorting Cells and Summing Totals

    BUYSHEET TEST.xlsm
    EDIT :This is the same attachment as in the first post... I attached it before I realized I could edit my first post to include it...

    I have attached the a workbook that contains the before and after sheets, as well as an existing macro.

    Please use this when making suggestions.
    Last edited by ahilty; 07-12-2013 at 01:25 PM.

  9. #9
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,052

    Re: Annoying Macro - Sorting Cells and Summing Totals

    I'm a little confused as to what you want to do. "Before Sheet1" and "After Sheet1" appear to be exactly the same. Do you want "Before Sheet2" to be made to look like "After Sheet2"? Please provide more detail. How many and which sheets are you actually working with and what exactly do you want to do with those sheets?

  10. #10
    Registered User
    Join Date
    07-08-2013
    Location
    Fort Wayne, IN
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: Annoying Macro - Sorting Cells and Summing Totals

    Yes - I tried to make it more clear by using red font on AFTER SHEET1.

    "Sheet1" will not be affected; it is solely used to copy information from.

    "After Sheet2 is the final product. How I would like it to look like.
    - Note that the only column that needs to be sorted is column A. Column B (even though it wouldn't be difficult to also sort that as a secondary column should not be sorted. This is because job costs in that field that are related are normally kept beside one another (not in any alphabetical order).

    Thanks again Mumps,

  11. #11
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,052

    Re: Annoying Macro - Sorting Cells and Summing Totals

    Let's try this attachment.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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