I haven't had time to analyze this mathematically to find the optimal algorithm, but it sounds like you may be content with a brute force approach.
Open a copy of your workbook. Press Alt-F11 to open the VBA editor. From the menu, click Insert > Module. On the sheet that opens, paste this code:
Code:
Public Function GetDiff(ByVal a, ByVal b, ByVal d, ByVal LL, ByVal UL)
Dim i As Long, j As Long
For i = LL To UL
For j = LL To UL
If Round(Abs(i * a - j * b), 10) = d Then
GetDiff = a & " * " & i & " - " & b & " * " & j & " = " & i * a - j * b
Exit Function
End If
Next j
Next I
GetDiff = "No answer found"
End Function
Now press Alt-Q to close the editor. Now you can use that function in your worksheet like this:
Excel 2012
| B | C | D | E |
---|
0.74 * 14 - 1.56 * 6 = 1 | | | | |
0.47 * 36 - 1.28 * 14 = -1 | | | | |
No answer found | | | | |
47 * 49 - 128 * 18 = -1 | | | | |
0.235 * 72 - 1.28 * 14 = -1 | | | | |
<colgroup><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]
[TD="align: right"]0.74[/TD]
[TD="align: right"]1.56[/TD]
[TD="align: right"][/TD]
[TD="align: center"]2[/TD]
[TD="align: right"]0.47[/TD]
[TD="align: right"]1.28[/TD]
[TD="align: right"][/TD]
[TD="align: center"]3[/TD]
[TD="align: right"]74[/TD]
[TD="align: right"]156[/TD]
[TD="align: right"][/TD]
[TD="align: center"]4[/TD]
[TD="align: right"]47[/TD]
[TD="align: right"]128[/TD]
[TD="align: right"][/TD]
[TD="align: center"]5[/TD]
[TD="align: right"]0.235[/TD]
[TD="align: right"]1.28[/TD]
[TD="align: right"][/TD]
</tbody>
Sheet1
[TABLE="width: 85%"]
<tbody>[TR]
[TD]
Worksheet Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: #DAE7F5"]
[TH="width: 10"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10, bgcolor: #DAE7F5"]D1[/TH]
[TD="align: left"]=Getdiff(
B1,C1,1,1,100)[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
Put the formula in D1 and drag down. The parameters in the function are:
The first number
The second number
The difference you want to find
The lower limit of the integer range you want to test
The upper limit of the integer range you want to test
I used 1-100 in this example, and it found answers to 4 out of 5 of the test cases you proposed. If you don't get an answer, you can change the lower/upper limits.
HOWEVER, the higher you raise the limits, the longer it may take, and your sheet may bog down entirely.
ALSO, some answers will
NOT have a solution! No matter how high you raise the limits, the problem in row 3 will never have an answer. I have analyzed that particular problem, and that's pretty easy to prove. So don't think that if you raise the limits high enough you'll get an answer, because you won't.
I have a program that uses the Extended Euclidean Algorithm to show immediately which problems have an answer or not, but I haven't had time to adapt it to your problem. Hopefully, the UDF provided will be sufficient for your needs.