Simple (?) math problem

MAYFIELDEXCEL

New Member
Joined
Apr 10, 2019
Messages
2
You are given a random number. For this example lets use 1793
You are then given some additional numbers. For this example lets use 16, 17, & 18.

What I want to do is list out the different sets of these numbers that would equal the random number.

Some examples (Not showing them all because I don't want to have to do the math)
- ( 17 X 1 ) + ( 16 X 111 ) = 1793
- ( 17 X 97 ) + ( 18 X 8 ) = 1793

So two sets or answers would be
17x1
16x111

&

17x97
18x8

I have no idea how to do this. Any help would be greatly appreciated!
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
I am not sure that I am correctly understand but check something like:


Code:
Sub A()
Dim ToReach As Long
Dim X1, X2, X3 As Long
Dim x, y, z As Long
Dim counter As Long
Application.ScreenUpdating = False
counter = 10
Range("A10:C50000").ClearContents
ToReach = Range("A3").Value
X1 = Range("B3").Value
X2 = Range("C3").Value
X3 = Range("D3").Value


For x = 1 To ToReach
    For y = 1 To ToReach
        If ((X1 * y) + (X2 * x)) = ToReach Then
            Range("A" & counter).Value = "((" & X1 & "*" & y & ") + (" & X2 & "*" & x & ")) ="
            Range("C" & counter).Value = "=((" & X1 & "*" & y & ") + (" & X2 & "*" & x & "))"
            counter = counter + 1
        End If
        If ((X1 * y) + (X3 * x)) = ToReach Then
            Range("A" & counter).Value = "((" & X1 & "*" & y & ") + (" & X3 & "*" & x & ")) ="
            Range("C" & counter).Value = "=((" & X1 & "*" & y & ") + (" & X3 & "*" & x & "))"
            counter = counter + 1
        End If
        If ((X2 * y) + (X3 * x)) = ToReach Then
            Range("A" & counter).Value = "((" & X2 & "*" & y & ") + (" & X3 & "*" & x & ")) ="
            Range("C" & counter).Value = "=((" & X2 & "*" & y & ") + (" & X3 & "*" & x & "))"
            counter = counter + 1
        End If
    Next y
Next x
Application.ScreenUpdating = True
End Sub


Data in cells:
A3: number to reach
B3/C3/D3 - 3 numbers to solve
 
Upvote 0
Yeah, actually that's it exactly. Amazing!

If I wanted to add another value would I just add it like this:

Code:
Dim X1, X2, X3, X4 As Long
Dim x, y, z As Long
Dim counter As Long
Application.ScreenUpdating = False
counter = 10
Range("A10:C50000").ClearContents
ToReach = Range("A3").Value
X1 = Range("B3").Value
X2 = Range("C3").Value
X3 = Range("D3").Value
X4 = Range("E3").Value

Or would I need to add more to the if then section? Essentially If I want more than three variables?
 
Upvote 0
X4 as You said.
Also add IFs with multiplying.
Now you got X1*X2 / X1*X3 / X2*X3 and you have to add X1*X4 / X2*X4 / X3*X4.
 
Upvote 0

Forum statistics

Threads
1,215,432
Messages
6,124,859
Members
449,194
Latest member
HellScout

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top