+ Reply to Thread
Results 1 to 9 of 9

Calculate formulas/UDFs from input and outputs

  1. #1
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Calculate formulas/UDFs from input and outputs

    This is almost certainly the most unusual question I have ever posted (or ever will post) on this forum.

    I have known inputs and (sorta) known outputs and I need Excel formulas (or better still - UDFs) to calculate the outputs.

    First picture a user form that we want to place X number of buttons on it (it doesn't matter if you are not familiar with forms - picture cardboard boxes instead). The buttons/boxes are all the same size and will be in alignment with each other. They will be laid out in the shape of a rectangle. I need to calculate 1. the number of rows and 2. the number of columns for any number of buttons/boxes.

    Now the tricky bit - there are two goals we need to meet when calculating the number of rows/columns:
    1. Try to keep the number of boxes on the last row as close as possible to the total no. of columns - in other words, keep gaps to a minumum. I can't have a last row with only one box/button on it.
    2. Try to keep the rows/column ratio to a visually pleasing ratio (aiming between 1.2 to 1.7. This is not as critical as the previous goal)

    It might be easier to work out what I am after by referring to the attached workbook.

    So can this be expressed as an Excel formula? If you prefer to calculate this using VBA, a UDF would be great
    Attached Files Attached Files
    *******************************************************

    HELP WANTED! (Links to Forum threads)
    Trying to create reusable code for Custom Events at Workbook (not Application) level

    *******************************************************

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Calculate formulas/UDFs from input and outputs

    So what is your expected result and where you shown in the excel file?


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Calculate formulas/UDFs from input and outputs

    Quote Originally Posted by :) Sixthsense :) View Post
    So what is your expected result and where you shown in the excel file?
    From input (Column A), I want to return/output two results (Column E & F).

    I use Columns H to P to test what outputs I need.

    To give an example:

    Take input of 40. I am hoping for an output result of 8 rows by 5 columns.
    If I had outputs of 7x6, I would have a total of 42. This result would not be as desirable as 8x5 because 7x6 would have two gaps (42-40=2)
    If I had outputs of 10x4, I would have a total of 40 (no gaps). However this is not as desirable as 8x5 because the ratio of the 10x4 rectangle would be 2.5 (10/4=2.5) (8/5=1.6 which is in the ratio I am aiming for)

  4. #4
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Calculate formulas/UDFs from input and outputs

    I believe that there is an area of mathematics which specialises in this. Calculate an area to hold a known quantity with minimal mumber of gaps/space left over.

  5. #5
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Calculate formulas/UDFs from input and outputs

    Now I can understand your logic clearly and I can’t able to achieve this without using VBA… Is it ok for you? Because for finding the nearest match I need to use multiplication table via vba and even the VBA can be avoided if I have the table in excel…

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

    Re: Calculate formulas/UDFs from input and outputs

    What's the objective function to maximize?

    If 34 boxes were needed, how would they be arranged? What's the relative figure of merit between skinny filled rectangles and square-ish partially-populated rectangles?
    Last edited by shg; 10-18-2013 at 01:49 AM.
    Entia non sunt multiplicanda sine necessitate

  7. #7
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Calculate formulas/UDFs from input and outputs

    I thought I can make a multiplication table and compare the values using Vlookup with Approximate & Exact Match… But I don’t have much time to do that… So anyone I just wanted to share what I arrived so far…

    The below will create multiplication table with ratio and sort the data using the values…

    Please Login or Register  to view this content.

  8. #8
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Calculate formulas/UDFs from input and outputs

    Quote Originally Posted by shg View Post
    What's the objective function to maximize?

    If 34 boxes were needed, how would they be arranged? What's the relative figure of merit between skinny filled rectangles and square-ish partially-populated rectangles?
    Very good questions.

    34 boxes is 7 rows by 5 columns (refer row 26 on uploaded workbook).

    The objectives are:

    To display buttons on a userform so that the number of macro buttons passed will fill the total columns and total rows as neatly as possible (i.e. keeping number of gaps on the last row to a minimum).

    At the same time, the user form shouldn't be difficult to read. By that I mean that the form shouldn't be stretched too far vertically or horizontally - so I am aiming for a optimum ratio of between ~1.2 to ~1.7 on row number to column number. However if the ratio would have to exceed these limits in order to prevent having 1 button on the last row (see my comment in cell P13) then so be it.

    This is not easy for me to explain, which is why I uploaded the workbook to show examples of the rows & columns I am aiming for (column E & F) and why (column P and conditional formatting in columns H-N)

    I guess the processing priority is as follows:
    1. Avoid having only 1 button on the last row
    2. Try to fill the grid as closely as possible/keep gaps to a minimum
    3. Aim for a ratio of between ~1.2 to ~1.7 on rows to columns

    Goal 3 is more of a guide to what to choose after goals 1 & 2 are completed. For example an input of 24. This can perfectly divide into 12:2 or 8:3 or 6:4. Yet 6:4 is the only one of these three in the desired ratio range. So the functions should return 6 rows and 4 columns.

    Having said that: Goal 3 can sometimes take priority over Goal 2; If all results for an input return say 2-4 gaps each (all results almost as bad as each other) then aim for the result which returns the best ratio.
    Last edited by mc84excel; 10-20-2013 at 07:25 PM.

  9. #9
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Calculate formulas/UDFs from input and outputs

    I don't know if this will help or hinder solving this thread.

    To see the bigger picture of what I am trying to achieve here with button/box layouts, please see this thread http://www.excelforum.com/excel-prog...t-runtime.html

+ 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. [SOLVED] UDFs - Improve to automatically update when input changes
    By JungleJme in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-20-2013, 11:10 AM
  2. Sensitivity Table: 1 input, 2 outputs
    By Cheathering in forum Excel General
    Replies: 1
    Last Post: 09-14-2011, 11:26 AM
  3. One row of input, two rows of outputs
    By GoodGuyGary in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-09-2009, 06:19 AM
  4. 1 VLOOKUP/IF Input and 2 Outputs? How?
    By tdglogik in forum Excel General
    Replies: 5
    Last Post: 07-21-2007, 05:00 AM
  5. [SOLVED] Evaluate method - UDFs and Formulas
    By mo_in_france in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-14-2005, 05:06 PM

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