+ Reply to Thread
Results 1 to 9 of 9

To reach a Value (or closest to it) with all 14 elements

  1. #1
    Registered User
    Join Date
    12-04-2023
    Location
    Slovenia
    MS-Off Ver
    2010
    Posts
    53

    To reach a Value (or closest to it) with all 14 elements

    Only addition and subtraction operations (+ and -) are available among 14 chosen elements.

    The task is to reach chosen Value (or closest value with minimal difference to it) with all 14 chosen elements (natural numbers), always written in column from smallest to largest.

    Minimum difference: this is the one that is the lowest possible.
    This does not mean that the difference is no more than 1 to the selected value (which should be approached).
    It can be any, but the lowest possible (reached with 14 natural numbers) difference to the selected value, if an accurate result is not found.

    Value to reach and 14 natural numbers are INPUT, and all can be large.

    Possible to solve in Excel 2010 (write a macro)?

    Thank you very much.

    Kind regards,

    Sasa
    Attached Files Attached Files
    Last edited by sasamaribor; 12-11-2023 at 03:17 AM.

  2. #2
    Forum Contributor
    Join Date
    11-23-2022
    Location
    Amsterdam
    MS-Off Ver
    2021
    Posts
    193

    Re: To reach a Value (or closest to it) with all 14 elements

    Please try this. It's pretty neat, working with the Dec2Bin instruction (here in a slightly modified form to allow for numbers exceeding 512) to systematically scan binary sequences of 14 digits long to probe all possibilities of addition (1) or subtraction (0). Furthermore, I have made it dynamic to deal with different target numbers and 14 freely adjustable integers. Note that there might be multiple answers but that it stops at the first hit.

    Please Login or Register  to view this content.
    Sample file here: Value to reach.xlsm
    Cheers.
    Last edited by kaasplankje; 12-10-2023 at 06:30 PM.

  3. #3
    Registered User
    Join Date
    12-04-2023
    Location
    Slovenia
    MS-Off Ver
    2010
    Posts
    53

    Re: To reach a Value (or closest to it) with all 14 elements

    Hello,

    In example I attached it is: 1+2+3-4+5-6+7+8-9-10+11+12-13+14 = 21

    I have just opened your xlsm file. I do not see nothing there. Just changed + and - in green column. But such order do not give result 25 with all 14 elements.

    So i do not understand that file you have sent me.

    I am not programmer.

    What should i do with "program" you attach in picture above? Write all that in Excel 2010 in cells? I supose not, hm...

    Thank you very much. I appreciate your efforts.

    Sasa
    Last edited by sasamaribor; 12-10-2023 at 12:39 PM.

  4. #4
    Forum Contributor
    Join Date
    11-23-2022
    Location
    Amsterdam
    MS-Off Ver
    2021
    Posts
    193

    Re: To reach a Value (or closest to it) with all 14 elements

    Youi must run the macro. This will fill the correct pluses and minuses and show the best possible answer.
    Last edited by kaasplankje; 12-10-2023 at 12:41 PM.

  5. #5
    Registered User
    Join Date
    12-04-2023
    Location
    Slovenia
    MS-Off Ver
    2010
    Posts
    53

    Re: To reach a Value (or closest to it) with all 14 elements

    How I run the macro? I do not see any button.

  6. #6
    Forum Contributor
    Join Date
    11-23-2022
    Location
    Amsterdam
    MS-Off Ver
    2021
    Posts
    193

    Re: To reach a Value (or closest to it) with all 14 elements

    Well, yes that could be possible as well. But please introduce yourself to the vba editor first and follow these steps: https://support.microsoft.com/en-us/...3-50e645fe3155

  7. #7
    Registered User
    Join Date
    12-04-2023
    Location
    Slovenia
    MS-Off Ver
    2010
    Posts
    53

    Re: To reach a Value (or closest to it) with all 14 elements

    Hello, I manage to do.

    Perhaps we did not understand ourselves about the minimum difference. This is the one that, with 14 natural numbers selected, is the lowest possible. This does not mean that the difference is no more than 1 to the selected value (which should be approached). It can be any, but the lowest possible difference to the selected value, if an accurate result is not found.

    Is it possible to change something to a macro so that any natural number can be entered?

    There are a maximum of 14 natural numbers, but they can be large.

    The same applies to the number we want to approach it, it can be a large natural number.

    Thank you very very much!
    Last edited by sasamaribor; 12-10-2023 at 02:12 PM.

  8. #8
    Valued Forum Contributor Hydraulics's Avatar
    Join Date
    07-15-2018
    Location
    Udine - Italy
    MS-Off Ver
    Office 365
    Posts
    373

    Re: To reach a Value (or closest to it) with all 14 elements

    Here is a solution based on Solver. You may need to load the Add-In first.

    Once it is available, just run it. Variables and constraints are in columns L-N.

    HTH,

    Francesco
    Attached Files Attached Files
    Aim high or don't even try.
    ---------------------------------
    If your question has been answered, don't forget to mark the thread as SOLVED.
    If you find an answer helpful, click on the star icon at the bottom of the post.

  9. #9
    Forum Contributor
    Join Date
    11-23-2022
    Location
    Amsterdam
    MS-Off Ver
    2021
    Posts
    193

    Re: To reach a Value (or closest to it) with all 14 elements

    Sorry but it seems you are asking for a finger and then try to take my hand. Please get yourself familiarized with macros and try yourself. You now have two good answers to play with.

+ 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. Replies: 11
    Last Post: 06-05-2023, 01:36 AM
  2. Scrape web data using multiple elements (sub elements)
    By Snoddas in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-19-2019, 01:56 PM
  3. [SOLVED] Excel IsNumber Function treats array elements differently from range elements
    By Alan Beban in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-31-2018, 02:22 PM
  4. [SOLVED] Retrieving the Closest Larger / Closest Smaller Values from a List
    By ChipsSlave in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 03-31-2017, 08:38 AM
  5. Resources for Using VBA to Manipulate Silverlight Elements like HTML Elements
    By linear_db in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-16-2013, 04:43 PM
  6. [SOLVED] get 10 Closest Larger / Closest Smaller Values from a List
    By Auni in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-19-2013, 04:07 AM
  7. Replies: 0
    Last Post: 08-25-2005, 02:37 AM

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