+ Reply to Thread
Results 1 to 22 of 22

Create new set of numbers based on conditional rules

  1. #1
    Registered User
    Join Date
    11-18-2009
    Location
    Selangor, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    21

    Create new set of numbers based on conditional rules

    Hi guys,

    I have this situation: Let's say I have 35 blank cells in a row to be filled up with numbers. Whenever a set of numbers being filled up in the blank cells, excel will generate a new set of numbers derived from that first set input numbers in a new row below the first set with the criteria below :

    1. Any 2 adjacent numbers in the row in the first set will be added together whenever that 2 numbers are lesser than 10.

    2. Any 2 adjacent numbers in the first set with the value of more than 10 will remain as it's original value.

    3. Any 2 adjacent numbers in the first set with the value of more than 10 and less than 10 will remain as it's original value.

    Example 1:

    First Set : 2,1,3,4,9,8,6,1,2,7,7,8,5,3,4,2,9,7,8,4,8,6,5,9,2,1,1,8,7,6,5,3,2,1,8
    Result : 3,7,17,7,9,15,8,6,16,12,14,14,3,9,13,8,3,8

    Example 2:

    First Set : 12,21,34,45,19,86,76,11,42,75,17,68,15,13,47,23,29,66,87,14,18,16,53,93,22,12,21,48,17,16,15,13,21,11,18
    Result : 12,21,34,45,19,86,76,11,42,75,17,68,15,13,47,23,29,66,87,14,18,16,53,93,22,12,21,48,17,16,15,13,21,11,18

    Example 3:

    First Set : 13,5,12,1,12,5,3,1,13,1,12,1,25,19,9,1,25,22,15,14,14,5,3,8,9,1,3,14,2,9,11,7,15,15,4
    Result : 13,5,12,1,12,8,1,13,1,12,1,25,19,10,25,22,15,14,14,8,17,4,14,11,11,7,15,15,4

    Really appreciate your help on this matter.
    Last edited by promo786; 11-13-2011 at 08:46 AM. Reason: wrong word being use. should be "based on conditional rules" not "with conditional format"

  2. #2
    Forum Contributor
    Join Date
    11-04-2011
    Location
    pak
    MS-Off Ver
    Excel 2007
    Posts
    132

    Re: Create new set of numbers with conditional format

    why man, your problem was to repeat a charcter starting from 1,2,3...35 times per each cell. this is another problem. :S

  3. #3
    Registered User
    Join Date
    11-18-2009
    Location
    Selangor, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Create new set of numbers with conditional format

    Quote Originally Posted by shaukat View Post
    why man, your problem was to repeat a charcter starting from 1,2,3...35 times per each cell. this is another problem. :S
    Bro. shaukat,

    as i mentioned in my earlier post in the other thread, i have wrongly stating my question there. And you are right when interpretating that question. I consider my question there has been answered.

    Now, in this thread i have composed my question again to give clear picture on the situation that i'm currently need to solve it. Appreciate your help or any other members here who could give a hand on this matter.

    For additional info : I'm doing a project whereby i need to convert any words (max of 35 characters) into numbers (each alphabet is assign with certain number). From the numbers generated, i need to do some calculation based on sets of rules as mentioned above.

  4. #4
    Forum Contributor
    Join Date
    11-04-2011
    Location
    pak
    MS-Off Ver
    Excel 2007
    Posts
    132

    Re: Create new set of numbers with conditional format

    for example, take first case:

    2,1,3,4,9,8,10,1,2,7,7,8,5,3,4,2,9,7,8,11,8,6,5,9,2,1,1,8,7,6,5,3,2,1,8
    result : 3,7,17,10,1,9,15,8,6,16,8,11,14,14.......... is this ok?
    Last edited by shaukat; 11-13-2011 at 06:15 AM.

  5. #5
    Registered User
    Join Date
    11-18-2009
    Location
    Selangor, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Create new set of numbers with conditional format

    Quote Originally Posted by shaukat View Post
    for example, take first case:

    2,1,3,4,9,8,10,1,2,7,7,8,5,3,4,2,9,7,8,11,8,6,5,9,2,1,1,8,7,6,5,3,2,1,8
    result : 3,7,17,10,1,9,15,8,6,16,8,11,14,14.......... is this ok?
    The result should be : 3,7,17,10,3,14,13,7,11,15,11,14,14..........

    Explaination :

    2 & 1 (both are less than 10 individually), so 2 + 1 = 3,

    the next no. is 3 and since no 4 is next to it also less than 10, 3 + 4 = 7,

    after that is no 9 and no 8 (both are also less than 10 individually), so 9 + 8 = 17,

    right after that is no 10 and no 1, since only 1 number is less than 10, no. 10 remain,

    continue again with no. 1 and next to it is no 2 (both are less than 10 individually, so 1 + 2 = 3,

    and so on....


    Rules: as long as the 2 numbers adjacent are less than 10, it will be added together or else it will remain as it is..

  6. #6
    Registered User
    Join Date
    11-18-2009
    Location
    Selangor, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Create new set of numbers with conditional format

    Quote Originally Posted by royUK View Post
    How is Conditional Formatting involved?
    royUK,

    thanks for the question. I just realised that no conditional formatting involved.

    I have changed the title. It should be "Create new set of numbers based on conditional rules" not "Create new set of numbers with conditional format".

  7. #7
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Create new set of numbers based on conditional rules

    Maybe so? 1st row on the sheet - the original set, 2nd row - the result.
    Please Login or Register  to view this content.
    Last edited by nilem; 11-13-2011 at 08:19 AM.

  8. #8
    Registered User
    Join Date
    11-18-2009
    Location
    Selangor, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    21

    Thumbs up Re: Create new set of numbers based on conditional rules

    Quote Originally Posted by nilem View Post
    Maybe so? 1st row on the sheet - the original set, 2nd row - the result.
    Please Login or Register  to view this content.
    Thank you very much nilem. Excellent! This is what i need.

  9. #9
    Forum Contributor
    Join Date
    11-04-2011
    Location
    pak
    MS-Off Ver
    Excel 2007
    Posts
    132

    Re: Create new set of numbers based on conditional rules

    @ Nilem very good script , however
    series: 1 2 4 10 1 5 7 10 1 11 3 12 1
    result: 3 4 10 6 7 10 1 11 3 12 1
    the last 3 and 1 should be summed up. what is your opinon?
    result: 3 4 10 6 7 10 1 11 12 4

  10. #10
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Create new set of numbers based on conditional rules

    Hi Shaukat
    I proceeded from the fact that
    Any 2 adjacent numbers in the row in the first set will be added together...

  11. #11
    Registered User
    Join Date
    11-18-2009
    Location
    Selangor, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Create new set of numbers based on conditional rules

    Quote Originally Posted by nilem View Post
    Hi Shaukat
    I proceeded from the fact that
    Yes nilem. You've got it right.

    nilem,

    if you don't mind, how about to set the result to minimum of 4 digit. The operation stops whenever the end result equals to 4 digits.

    Example :

    First Set : 2,1,3,4,9
    Result : 3,3,4,9

    Thanks.

  12. #12
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Create new set of numbers based on conditional rules

    If understood correctly ... Try to add the red line
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    11-18-2009
    Location
    Selangor, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Create new set of numbers based on conditional rules

    Quote Originally Posted by nilem View Post
    If understood correctly ... Try to add the red line
    Please Login or Register  to view this content.
    nilem,

    here are examples to explain the expected results:

    Example 1:

    First Set : 2,1,3,4,9 ==> no's 2 & 1 are added together, the remaining 3 no's remain
    Result : 3,3,4,9 ==> the result must be minimum 4 digits


    Example 2:

    First Set : 21,3,4,9 ==> since there are only 4 digits, no need to add the numbers
    Result : 21,3,4,9 ==> the result must be minimum 4 digits


    Example 3:

    First Set : 9,3,4,9 ==> since there are only 4 digits, no need to add the numbers
    Result : 9,3,4,9 ==> the result must be minimum 4 digits


    Note: The user are allowed to input numbers from 4 - 35 digits only in the fisrt set row.

    Thanks for your help.

  14. #14
    Registered User
    Join Date
    11-18-2009
    Location
    Selangor, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Create new set of numbers based on conditional rules

    Example 4:

    First Set : 21,3,4,9,1
    Result : 21,7,9,1 ==> the result must be minimum 4 digits


    Example 5:

    First Set : 21,3,4,9,1,5,4
    Result : 21,7,10,9 ==> the result must be minimum 4 digits


    Example 6:

    First Set : 3,4,19,1,19
    Result : 7,19,1,19 ==> the result must be minimum 4 digits


    Example 7:

    First Set : 1,4,6,1,19
    Result : 5,6,1,19 ==> the result must be minimum 4 digits

  15. #15
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Create new set of numbers based on conditional rules

    Try this:
    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    11-18-2009
    Location
    Selangor, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Create new set of numbers based on conditional rules

    Quote Originally Posted by nilem View Post
    Try this:
    Please Login or Register  to view this content.
    I don't know how to thank you nilem. This code works perfectly. I have tested it for the below scenario :

    The input for numbers to be evaluated start from cell A1. After I executed the macro based on the code given, the result is generated start in cell C2 onwards.

    What if I need to put the numbers for the evaluation start in cell D12 and the result generated start in cell D13?

    Million thanks to you.

  17. #17
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Create new set of numbers based on conditional rules

    Quote Originally Posted by promo786 View Post
    What if I need to put the numbers for the evaluation start in cell D12 and the result generated start in cell D13?
    Write these lines
    Please Login or Register  to view this content.
    instead of these lines
    'With [c1].CurrentRegion
    ' a = .Rows(1).Resize(, .Columns.Count + 1).Value
    'End With: uba = UBound(a, 2): ReDim b(1 To uba)

    And write this line
    Please Login or Register  to view this content.
    instead of the
    '[c2].Resize(, uba).Value = b

  18. #18
    Registered User
    Join Date
    11-18-2009
    Location
    Selangor, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Create new set of numbers based on conditional rules

    Quote Originally Posted by nilem View Post
    Write these lines
    Please Login or Register  to view this content.
    instead of these lines
    'With [c1].CurrentRegion
    ' a = .Rows(1).Resize(, .Columns.Count + 1).Value
    'End With: uba = UBound(a, 2): ReDim b(1 To uba)

    And write this line
    Please Login or Register  to view this content.
    instead of the
    '[c2].Resize(, uba).Value = b
    Million thanks nilem

    It works!

  19. #19
    Registered User
    Join Date
    11-18-2009
    Location
    Selangor, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Create new set of numbers based on conditional rules

    Hi all,

    Anyone here could help me to solve the problem i'm facing here? I have successfully used the codes given to achieve my target however another problem occurred.

    Actually the original set of numbers that i wanted to convert based on the conditional rules are derived from a word via few excel formula/processes. After the word is converted to the relevant numbers, i ran a macro to convert it. Unfortunately, for certain words it failed to generate the correct result. (Refer to the file attached in tab "Kiraan").

    However, if i type in the same set numbers manually (not involving any excel formula/processes), the result generated after i ran the macro is correct. (Refer to the file attached in tab "Nama")

    Thanks in advance.
    Attached Files Attached Files

  20. #20
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Create new set of numbers based on conditional rules

    Try it (see attachment).
    Attached Files Attached Files

  21. #21
    Registered User
    Join Date
    11-18-2009
    Location
    Selangor, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Create new set of numbers based on conditional rules

    Thank again nilem. This is awesome. You have made the macro run automatically instead of manually executed.

    Referring to the code in the file :

    Please Login or Register  to view this content.
    What is "-4123" is referring to / how do you get the no.?

  22. #22
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Create new set of numbers based on conditional rules

    it means
    Please Login or Register  to view this content.
    Look the Help for VBA

+ 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