+ Reply to Thread
Results 1 to 5 of 5

How many values are used to make a certain value.

Hybrid View

  1. #1
    Registered User
    Join Date
    05-08-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    5

    How many values are used to make a certain value.

    Hello, I was wondering if someone could help me with this. I have attached my workbook to help you guys understand. It is just a sample though, as the file would have been too big to upload.

    Basically, in columns A,B,C and D I have 4 unique values. This goes on for about 150,000 records.
    I would like to know what is the minimum amount to use to make the values in row 1(column F onwards)

    For example, row 7 has values 1,2,3,9.
    To make 7, it would take 3 of the values (3,3,1)
    To make 8, it would take 3 of the values (3,3,2)
    To make 9, it would take 1 of the values (9)

    I attempted a huge IF function but it didn't come together as I thought it would.
    Has anyone any ideas on how to solve this? Maybe it needs VBA?

    Thanks in advance.
    Attached Files Attached Files

  2. #2
    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: How many values are used to make a certain value.

    What's the point of doing this?
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    05-08-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: How many values are used to make a certain value.

    I'm currently doing a project at University. Trying to find the most efficient way to add up to numbers 1-99 using just unique 4 values.
    If you ask why I'm doing this, I couldn't answer. The new breed of Mathematicians; doing things that don't need doing...

  4. #4
    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: How many values are used to make a certain value.

    Function HowMany(ByVal iSum As Long, rInp As Range) As Long
        Dim i           As Long
        Dim j           As Long
    
        For i = rInp.Cells.Count To 1 Step -1
            j = iSum \ rInp(i).Value
            iSum = iSum - rInp(i).Value * j
            HowMany = HowMany + j
        Next i
    End Function
          A B C D- E F G H I J K L M N O- P- Q- R- S- T- U-
      1   A B C D    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
      2   1 2 3  4   1 1 1 1 2 2 2 2 3  3  3  3  4  4  4  4
      3   1 2 3  5   1 1 1 2 1 2 2 2 3  2  3  3  3  4  3  4
      4   1 2 3  6   1 1 1 2 2 1 2 2 2  3  3  2  3  3  3  4
      5   1 2 3  7   1 1 1 2 2 2 1 2 2  2  3  3  3  2  3  3
      6   1 2 3  8   1 1 1 2 2 2 3 1 2  2  2  3  3  3  4  2
      7   1 2 3  9   1 1 1 2 2 2 3 3 1  2  2  2  3  3  3  4
      8   1 2 3 10   1 1 1 2 2 2 3 3 3  1  2  2  2  3  3  3
      9   1 2 3 11   1 1 1 2 2 2 3 3 3  4  1  2  2  2  3  3
    In F2 and copy across and down,

    =HowMany(F$1, $A2:$D2)

  5. #5
    Registered User
    Join Date
    05-08-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: How many values are used to make a certain value.

    Sorry I've taken a long time to reply.
    I can't thank you enough! It worked a charm!

    Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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