How to solve this problem? is it array?

DoubleScope

New Member
Joined
Feb 22, 2022
Messages
10
Office Version
  1. 2019
Platform
  1. Windows
  2. Mobile
I have to find how many x and y.
Example :
365.000 = (40.000 * x) + (55.000 * y), the answer is x =5, y = 3.
But formula in Excel?

365.000 = (40.000 * x) + (55.000 * y), the answer is x =5, y = 3.
200.000 = (40.000 * x) + (55.000 * y), the answer is x = 4, y =0.

Sometimes, i need another variable other than 40k and 55k, 75k, 50k.
Help ... I really appreciate it.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hi, can resolve through VBA.

Check below macro:

VBA Code:
Sub solveEquation()
Dim eq As String, LHS As Long
Dim equalsignPos As Integer, xQty As Long, yQty As Long
Dim plussignPos As Integer
Dim xval As Integer, yval As Integer, result As Long

eq = WorksheetFunction.Substitute(Range("A1"), " ", "")  'Equation to solve

equalsignPos = InStr(1, eq, "=")    'position of equal = sign (9)
plussignPos = InStr(1, eq, "+")     'position of plus + sign (24)

LHS = Trim(Left(eq, equalsignPos - 1)) 

xQty = Trim(Mid(eq, InStr(1, eq, "(") + 1, InStr(1, eq, "*") - InStr(1, eq, "(") - 1))

yQty = Trim(Mid(eq, InStr(1, eq, "+(") + 2, InStr(InStr(1, eq, "*") + 1, eq, "*") - InStr(1, eq, "+(") - 2))

For xval = 0 To LHS
    For yval = 0 To LHS
        result = (xQty * xval) + (yQty * yval)
        If result = LHS Then
            MsgBox "x=" & xval & vbNewLine & "y=" & yval
            Exit For
        End If
    Next
Next

End Sub
 
Upvote 0
Hi, can resolve through VBA.

Check below macro:

VBA Code:
Sub solveEquation()
Dim eq As String, LHS As Long
Dim equalsignPos As Integer, xQty As Long, yQty As Long
Dim plussignPos As Integer
Dim xval As Integer, yval As Integer, result As Long

eq = WorksheetFunction.Substitute(Range("A1"), " ", "")  'Equation to solve

equalsignPos = InStr(1, eq, "=")    'position of equal = sign (9)
plussignPos = InStr(1, eq, "+")     'position of plus + sign (24)

LHS = Trim(Left(eq, equalsignPos - 1))

xQty = Trim(Mid(eq, InStr(1, eq, "(") + 1, InStr(1, eq, "*") - InStr(1, eq, "(") - 1))

yQty = Trim(Mid(eq, InStr(1, eq, "+(") + 2, InStr(InStr(1, eq, "*") + 1, eq, "*") - InStr(1, eq, "+(") - 2))

For xval = 0 To LHS
    For yval = 0 To LHS
        result = (xQty * xval) + (yQty * yval)
        If result = LHS Then
            MsgBox "x=" & xval & vbNewLine & "y=" & yval
            Exit For
        End If
    Next
Next

End Sub
Thanks i'll try.
But Im still curious formula code in excel (non-VBA).
 
Upvote 0
But Im still curious formula code in excel (non-VBA).
Welcome to the Forum!

Like this perhaps:

ABCDE
1
23654055
353
4
52004055
650
7
8802040
902
1021
1140
12
Sheet2
Cell Formulas
RangeFormula
C3,C9:C11,C6C3=LET(s,SEQUENCE(1+B2/C2,,0),FILTER(s,MOD(B2-s*C2,D2)=0))
D3,D9:D11,D6D3=(B2-C2*C3#)/D2
 
Upvote 0
1645694390550.png
1645694437372.png

Sorry, i dont understand. I just copied your formula. And it didnt work.
 
Upvote 0
Welcome to the Forum!

Like this perhaps:

ABCDE
1
23654055
353
4
52004055
650
7
8802040
902
1021
1140
12
Sheet2
Cell Formulas
RangeFormula
C3,C9:C11,C6C3=LET(s,SEQUENCE(1+B2/C2,,0),FILTER(s,MOD(B2-s*C2,D2)=0))
D3,D9:D11,D6D3=(B2-C2*C3#)/D2
Sorry, i dont understand. I just copied your formula. And it didnt work.
Look my post before.
 
Upvote 0
It looks like you don't have the LET function. Does this work:

ABCD
1
23654055
353
4
52004055
650
7
8802040
902
1021
1140
12
Sheet1
Cell Formulas
RangeFormula
C3,C9:C11,C6C3=FILTER(SEQUENCE(1+B2/C2,,0),MOD(B2-SEQUENCE(1+B2/C2,,0)*C2,D2)=0)
D3,D9:D11,D6D3=(B2-C2*C3#)/D2
 
Upvote 0
It looks like you don't have the LET function.
From the image, to me it looks like the FILTER function is identified as a problem.

Just guessing: Possibly a language function translation issue?
Or perhaps even a formula separator issue and it could be this?

=LET(s;SEQUENCE(1+B2/C2;;0);FILTER(s;MOD(B2-s*C2;D2)=0))
 
Upvote 0
From the image, to me it looks like the FILTER function is identified as a problem.

Just guessing: Possibly a language function translation issue?
Or perhaps even a formula separator issue and it could be this?

=LET(s;SEQUENCE(1+B2/C2;;0);FILTER(s;MOD(B2-s*C2;D2)=0))
Yes from image, you can see FILTER Function is the main problem.

And im using , as separator.
 
Upvote 0
It looks like you don't have the LET function. Does this work:

ABCD
1
23654055
353
4
52004055
650
7
8802040
902
1021
1140
12
Sheet1
Cell Formulas
RangeFormula
C3,C9:C11,C6C3=FILTER(SEQUENCE(1+B2/C2,,0),MOD(B2-SEQUENCE(1+B2/C2,,0)*C2,D2)=0)
D3,D9:D11,D6D3=(B2-C2*C3#)/D2
From 2nd image, you can see FILTER Function is the main problem.
Thanks.
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,390
Members
448,957
Latest member
Hat4Life

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