+ Reply to Thread
Results 1 to 22 of 22

Sequence of numbers (separated by zeros) with highest SUM

  1. #1
    Registered User
    Join Date
    12-14-2016
    Location
    Lisbon
    MS-Off Ver
    2013
    Posts
    16

    Sequence of numbers (separated by zeros) with highest SUM

    Hi guys

    I have a column (a big column) with a sequence of numbers separated by zeros. I want to know how i can copy to another column the sequence of numbers (separated by zeros) that is SUM is the highest.
    I give you an example below:

    A B
    0
    1
    2
    0
    1
    2
    3
    0
    1 1
    2 2
    3 3
    4 4
    0

    Thank you guys

  2. #2
    Forum Expert tim201110's Avatar
    Join Date
    10-23-2011
    Location
    Russia
    MS-Off Ver
    2016, 2019
    Posts
    2,357

    Re: If, else statement

    finction index, max, agregate
    Attached Files Attached Files

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

    Re: If, else statement

    Here, try this:
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    12-14-2016
    Location
    Lisbon
    MS-Off Ver
    2013
    Posts
    16

    Re: Sequence of numbers (separated by zeros) with highest SUM

    Thank you guys, but:

    tim201110, i dont want the SUM in another column, i want the numbers that make highest SUM.
    zbor, that formula work in my example but not in my real workboot.

    I will attach the workbook. (I have some columns and i have to do this for all of them, so the best thing for me is: if i have 20 columns, the formula must give me another 20 columns with that numbers i want)
    Attached Files Attached Files

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Sequence of numbers (separated by zeros) with highest SUM

    Result for first 10 columns:

    W
    X
    Y
    Z
    AA
    AB
    AC
    AD
    AE
    AF
    2
    10.7
    67.8
    25.2
    6.3
    18.5
    3.6
    18.2
    22.2
    10.4
    6.1
    3
    0.4
    1.4
    9.3
    9.5
    0.3
    2
    23.7
    4.1
    10.1
    4
    0.1
    4
    40.8
    25
    1.9
    6.5
    2.5
    7.7
    5
    3.2
    11.5
    34.9
    1.6
    2.7
    0.1
    2.6
    6
    0.1
    12.7
    19.5
    0.4
    10.1
    3.5
    7
    8.4
    3.4
    1.6
    0.2
    4.4
    8
    0.5
    1.6
    6
    3
    9
    8.7
    6.2
    0.9
    10
    2.5
    0.7
    11
    0.1


    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Sequence of numbers (separated by zeros) with highest SUM

    Try this sample
    Please Login or Register  to view this content.
    Attached Files Attached Files
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  7. #7
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Sequence of numbers (separated by zeros) with highest SUM

    Here's a Macro solution.
    You didn't specify where you wanted the found sequences put, so I added a sheet and the routine will put them there.
    I also added a cell with the sum above, but that can easily be removed from the Test sub.
    Attached Files Attached Files
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  8. #8
    Valued Forum Contributor kasan's Avatar
    Join Date
    07-22-2009
    Location
    Riga, Latvia
    MS-Off Ver
    Excel 2010
    Posts
    680

    Re: Sequence of numbers (separated by zeros) with highest SUM

    My try.
    You need to copy your data in column A of Sheet1, run macro and result will be in column B.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    12-14-2016
    Location
    Lisbon
    MS-Off Ver
    2013
    Posts
    16

    Re: Sequence of numbers (separated by zeros) with highest SUM

    Thank you guys, but:

    shg, you do it well but in my workbook that gave my an error: Set rInp = rInp.Offset(1).Resize(rInp.Rows.Count - 1)
    YasserKhalil, it works too, but in column L the sequence that appears is not the highest SUM
    mikerickson, that macro works but dont give me the right results
    kasan, doesnt work

  10. #10
    Valued Forum Contributor kasan's Avatar
    Join Date
    07-22-2009
    Location
    Riga, Latvia
    MS-Off Ver
    Excel 2010
    Posts
    680

    Re: Sequence of numbers (separated by zeros) with highest SUM

    @ Daniel88
    What do you mean by "does not work"? Some error or what?
    You need to be sure, that sheet name is "Sheet1" and copy only one column of data in column A. Then run macro and resulting sequence will be in column B - to the right of same sequence in column A.
    My file works fine with your data, at least for me on my PC.

  11. #11
    Registered User
    Join Date
    12-14-2016
    Location
    Lisbon
    MS-Off Ver
    2013
    Posts
    16

    Re: Sequence of numbers (separated by zeros) with highest SUM

    Kasan sorry, you are right. I forgot to check the numbers in the end of the column B. I was ready to find numbers right at the start. my bad

    Too much time on that "sheet"

    Thank you once again

  12. #12
    Valued Forum Contributor kasan's Avatar
    Join Date
    07-22-2009
    Location
    Riga, Latvia
    MS-Off Ver
    Excel 2010
    Posts
    680

    Re: Sequence of numbers (separated by zeros) with highest SUM

    It's Ok
    I should mention where my solution put the result in prev. post, actually I tried to make it like in your example in the first post.

  13. #13
    Registered User
    Join Date
    12-14-2016
    Location
    Lisbon
    MS-Off Ver
    2013
    Posts
    16

    Re: Sequence of numbers (separated by zeros) with highest SUM

    By the way, there is an solution to do this to all columns at the same time?? and maybe put the results on another sheet.
    Im asking this because i got a lot of data. This is the values from the precipitation, i got 4 meteorological station, where each one has 20 columns +-

  14. #14
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Sequence of numbers (separated by zeros) with highest SUM

    Try this
    Please Login or Register  to view this content.

  15. #15
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Sequence of numbers (separated by zeros) with highest SUM

    ... but in my workbook that gave my an error
    I ran that code on your workbook to get the posted result.

  16. #16
    Registered User
    Join Date
    12-14-2016
    Location
    Lisbon
    MS-Off Ver
    2013
    Posts
    16

    Re: Sequence of numbers (separated by zeros) with highest SUM

    I just reported what i saw. So i dont know why the error...
    i dont understand that programming stuff. I only do a copy/paste of the scripts that all of you give me and check the sheet and columns to see if it corresponds with the script.

  17. #17
    Valued Forum Contributor kasan's Avatar
    Join Date
    07-22-2009
    Location
    Riga, Latvia
    MS-Off Ver
    Excel 2010
    Posts
    680

    Re: Sequence of numbers (separated by zeros) with highest SUM

    Probably should work with all filled columns in sheet "Sheet1".
    Result should be in sheet "result".
    Columns 13 and 19 contains only 0, so no results for them.
    Attached Files Attached Files

  18. #18
    Registered User
    Join Date
    12-14-2016
    Location
    Lisbon
    MS-Off Ver
    2013
    Posts
    16

    Re: Sequence of numbers (separated by zeros) with highest SUM

    Ok, right, you the boss
    Works well. If i have more questions, you know what i will do

    Thank you again

  19. #19
    Valued Forum Contributor kasan's Avatar
    Join Date
    07-22-2009
    Location
    Riga, Latvia
    MS-Off Ver
    Excel 2010
    Posts
    680

    Re: Sequence of numbers (separated by zeros) with highest SUM

    Same logic, by now you can choose sum number, I mean enter 40 in Sheet1 cell X7 and macro will return all sequences with sum > 40 in sheet result.
    Attached Files Attached Files

  20. #20
    Registered User
    Join Date
    12-14-2016
    Location
    Lisbon
    MS-Off Ver
    2013
    Posts
    16

    Re: Sequence of numbers (separated by zeros) with highest SUM

    Probably I explained wrong. I dont want the sequence that sum is >40. I want the sequences that have >40 inside. like this:

    0
    10
    15
    20
    0
    10 10
    20 20
    45 45
    0

  21. #21
    Valued Forum Contributor kasan's Avatar
    Join Date
    07-22-2009
    Location
    Riga, Latvia
    MS-Off Ver
    Excel 2010
    Posts
    680

    Re: Sequence of numbers (separated by zeros) with highest SUM

    Ok, this one will return all sequences containing numbers greater than number from cell X7.
    Attached Files Attached Files

  22. #22
    Registered User
    Join Date
    12-14-2016
    Location
    Lisbon
    MS-Off Ver
    2013
    Posts
    16

    Re: Sequence of numbers (separated by zeros) with highest SUM

    Works well

    Thanks once again. I should put your name in my thesis

+ 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. How to count numbers in cells where several numbers are separated by /
    By Kreppie in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 07-07-2014, 09:01 AM
  2. Replies: 3
    Last Post: 08-20-2013, 03:59 AM
  3. [SOLVED] 2 separate columns with numbers separated by commas and single numbers not, need sum
    By Slothbob in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-22-2013, 04:33 PM
  4. [SOLVED] Generating 5 ones or zeros in a row, in any sequence with 3-2 proportion
    By szasz in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 04-21-2013, 05:17 AM
  5. [SOLVED] Creating a sequence based on numbers in one column and adding "01,02..." to a new sequence
    By JCR1968 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-05-2013, 08:06 AM
  6. Replies: 6
    Last Post: 02-24-2010, 11:48 PM
  7. Replies: 0
    Last Post: 08-08-2005, 01:05 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