+ Reply to Thread
Results 1 to 14 of 14

Sorting/counting/summing by step Macro help.

  1. #1
    Registered User
    Join Date
    01-25-2012
    Location
    Trenton, NJ
    MS-Off Ver
    Excel 2010
    Posts
    7

    Sorting/counting/summing by step Macro help.

    Hello Excel Forum Experts!

    This is my first post in what I hope will become an illustrious forum career. I regularly need to sort a data set by steps. The steps will be in pound increments with a corresponding, proportional number of units. The steps go from 1-10 and then in increments of 5 above 10. I've already created the code to create the steps and the corresponding increment numbers. The next step is the sorting. As you'll see in the attached image, I'd like to input the number of steps, the increment size, and the data list and have the macro create the table and count and sum the number of units in each step. For example, if there were three steps and the increment was 100, the steps would be 100, 200, and 300. If the data was 100,101,200, and 300, the steps would be 1-(1count, 100sum), 2-(2count, 201sum), 3-(1count, 300 sum). I'm thinking there will need to be another loop embedded in the one I have already, this one will populate the sum and count columns. Here is the code I've got so far:

    Please Login or Register  to view this content.
    Attachment 138058

    **Update - Attached worksheet. The steps and increments in the output table were populated by the macro, the sums and counts were manually calculated. I'm looking for an efficient way to count and sum based on step. I'd created a huge string of if's to do this, but creating it manually was cumbersome, and I'm sure there is a better way.Attachment 138072Attachment 138073
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by TCDataAnalyst; 01-25-2012 at 04:55 PM. Reason: Done some more work on code

  2. #2
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Sorting/counting/summing by step Macro help.

    hi TCDataAnalyst, welcome to Excelforum, it's always helpful to see an example worksheet with original data plus result you need to obtain.

  3. #3
    Registered User
    Join Date
    01-25-2012
    Location
    Trenton, NJ
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Sorting/counting/summing by step Macro help.

    Thanks for the feedback! Please let me know if there is anything else I could add to make my post more complete.

  4. #4
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Sorting/counting/summing by step Macro help.

    I'm afraid Attachment 138058 link is invalid, Macro Test Book.xlsx is valid but it is empty.

    To make a start I've made up my own file. Set values press the button.

    For now that's the only part clear to me. That's the VB option though this part can be easily handled with formulas only (I do not know what about the rest). The count and sum values are mistery so they are empty. Please provide some explanations on their calculation.

    PS. It looks I finally see what you mean. Will look at it tomorrow and post back
    Attached Files Attached Files
    Last edited by watersev; 01-25-2012 at 06:24 PM.

  5. #5
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Sorting/counting/summing by step Macro help.

    would still ask for explanation getting Count and Sum results as per gif file

  6. #6
    Registered User
    Join Date
    01-25-2012
    Location
    Trenton, NJ
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Sorting/counting/summing by step Macro help.

    I'm sorry for my vague posting and appreciate your piecing together my question for me. the list of data is packages and each one is the number of units in a package. The steps are by weight and the increment is the number of units per lb(Step). I need to sum the units for the packages in each weight range set and count them. and then total the columns. the units have to be less than or equal to the increment. for example 200 would be counted as a 200, but 201 might be counted as a 250.

    Please let me know if you have any more questions!

  7. #7
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Sorting/counting/summing by step Macro help.

    thanks, the question on your post #1 example:
    steps: 100, 200, 300
    increment: 100
    data: 100,101,200, 300
    steps - 100, count - 1, sum - 100 - clear
    steps - 200, count - 2, sum - 201 (100+101) - clear
    steps - 300, count - 1, sum - 300 - Not clear, why does count equals 1 and sum 300?

  8. #8
    Registered User
    Join Date
    01-25-2012
    Location
    Trenton, NJ
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Sorting/counting/summing by step Macro help.

    I've been busy working on this, and through my work, I can better explain my objective.

    I have a list of shipments that vary in size. I need to count the shipments and total the units per shipment by a pound/unit range. The Steps go from 1 to 10 and then in increments of 5 above 10. If a shipment has the exact amount of units in a step it is counted in that step, but if it's even one over, it is counted in the following step.

    My first for statements creates the table and embedded in there is another for loop that cycles through the shipments to see add/count the values to the current step.

    My code is sloppy because I'm pretty much going off logic and code pulled off the recorder.
    Please Login or Register  to view this content.
    The way i'm testing the shipment set is a little backwards, but it's the only way i could figure out right now. I'm currently getting an overflow error when I run the script.
    Attached Images Attached Images
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    01-25-2012
    Location
    Trenton, NJ
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Sorting/counting/summing by step Macro help.

    These are just Sums and counts for a data set. there was only 1(count) value that fell between 200 and 300, and that value was 300 units(sum). Is that clear?

  10. #10
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Sorting/counting/summing by step Macro help.

    Re: overflow error
    Change data type of LowEnd or Increment to Long instead of current Integer

    Logic of your posted examples is still not clear. Your posted code produces zeroes for all Pounds except 1. Please provide calculations for each Pounds as if you count that manually with explanations of what and why you are doing.

  11. #11
    Registered User
    Join Date
    01-25-2012
    Location
    Trenton, NJ
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Sorting/counting/summing by step Macro help.

    Step Creater-Sorter.GIF I actually figured out the long thing when i ran the program with more steps and saw that the error popped when the numbers hit the 1000's. I've attached a new image as well as my updated code. The program still generates 0's (except for row one), but I've manually entered the values and a brief explanation next to each of the drivers.

    *the image has mistakes is columns C18-C20, I'm missing a couple 0's, but the manually entered results are accurate.

    Here's my updated code, as well:

    Please Login or Register  to view this content.
    Thank you!
    Last edited by TCDataAnalyst; 01-30-2012 at 10:28 AM.

  12. #12
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Sorting/counting/summing by step Macro help.

    unfortunately due to site database error or recent upgrade your helpful attachment in post #11 is invalid. I've looked at it while going out of the office. I tried to replicate it now, hope I did not make mistakes. Here is the VB option. Please check attachment, press the button.
    Attached Files Attached Files
    Last edited by watersev; 01-31-2012 at 01:37 AM. Reason: corrected mistake within a code

  13. #13
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Sorting/counting/summing by step Macro help.

    as your post #11 attached gif is now viewable, I've modified the code to meet your output result and formatting. Some changes have been done to make it faster, please check attachment
    Attached Files Attached Files

  14. #14
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Sorting/counting/summing by step Macro help.

    formulas only option, amend ranges to suit your needs
    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