Looking for 1.00 difference in 2 columns

panyagak

Active Member
Joined
Feb 24, 2017
Messages
299
Hi.

Let me be brief:
I have values in 2 columns B & C.
Column A has 1,2,3,4,5,6,7,8.....to any number.

I need a code to multiply column A values with column B & C values separately with both resultant values substracting from each other until a 1.00 difference is detected.

Example (a): 0.74 and 1.56
14*0.74=10.36
6*1.56=9.36
Difference=1.00

Example (b): 0.47 and 1.28
36*0.47=16.92
14*1.28=17.92
Diff=1.00.

I did these 2 manually. Suppose I have over 1,000 of these?

Please HELP - my shoulders are aching.

Patrick
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Hi Eric W.

I still cant believe what your solution did to my analysis in terms of simplicity.

Its PURE EARTHLY MAGIC in IT!!!

YOU'RE A "WITCH" & MAGICIAN!!

Good day & God bless
 
Upvote 0
Those are some of the nicer things I've been called! :biggrin:

I wonder if I can get the powers that be here to change MVP to Magician? :confused:

I'm happy it worked for you.
 
Last edited:
Upvote 0
Hi Eric W.

This quizz can only be directed to you & countless thanks for solving it.

Is there a way by a code, to place into 2 separate columns the 2 values solved for the entire set, (eg. 6 & 14: 36 & 14 being 6 & 36 on its column and also 14 & 14)?

Cheers
Patrick
 
Upvote 0
Sure, there are a few ways to do that. We could convert the UDF into a regular macro and have it read down the column and have it place the answers in the columns as it goes. Or we could convert the UDF into an array formula and use Excel's normal function rules to get the various parts. Since that's quicker, I'll do that, but let me know if you want the other way.

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 = Array(i, j, i * a - j * b)
                Exit Function
            End If
        Next j
    Next I
    
    GetDiff = Array("N/A", "N/A", "N/A")
    
End Function
Install as before, or just change the 2 lines starting with "GetDiff = ".

To use it as an array formula:
Excel 2012
ABCDEFGHI
10.741.5614611461
20.471.283614-13614-1
374156N/AN/AN/AN/AN/AN/A
4471284918-14918-1
50.2351.287214-17214-1

<colgroup><col><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1

Worksheet Formulas
CellFormula
G1=INDEX(getdiff(A1,B1,1,1,100),1)
H1=INDEX(getdiff(A1,B1,1,1,100),2)
I1=INDEX(getdiff(A1,B1,1,1,100),3)

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>

Array Formulas
CellFormula
C1:E1{=getdiff(A1,B1,1,1,100)}

<thead>
</thead><tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>



There are 2 ways to do it. The first way is to select 3 cells, C1:E1, all at once, enter the formula, and confirm using Control+Shift+Enter. You can then copy and paste the 3 cells down the column.

The second way is to use INDEX to pull out the element from the array you want. The G1:I1 formulas are entered individually in their cells.

The first way is more efficient since it only makes the calculation once, whereas the second way does it 3 times.

Good luck!
 
Upvote 0
Solution
IT WORKED!!

There you go again, Eric W.

I"ll never forget your brilliant work.

You never know, I may soon request your Paypal details!!!

God bless you.
Cheers
 
Upvote 0
Eric W.

Good morning.

Thanks so far for "your only solutions".

Maths is endless:

Another 1.00 diff. maths problem. In this case let col. B remain unchanged as Col. A values vary.

Any approach using a CODE?

Eg.
Col. A Col. B Col. C
1.22 1.44 1.22*2-1.44=1.00
0.88 0.76 0.88*2-0.76=1.00
1.02 2.06 1.02*3-2.06=1.00
0.79 1.37 0.70*3-1.37=1.00
0.65 1.60 0.65*4-1.60=1.00
0.59 1.95 0.59*5-1.95=1.00
0.48 1.88 0.48*6-1.88=1.00

Thanks
Patrick
 
Upvote 0
That's just basic algebra:

Excel 2012
ABCDE
11.221.441.22*2-1.44=1.002
20.880.760.88*2-0.76=1.002
31.022.061.02*3-2.06=1.003
40.791.370.70*3-1.37=1.003
50.651.60.65*4-1.60=1.004
60.591.950.59*5-1.95=1.005
70.481.880.48*6-1.88=1.006

<colgroup><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1

Worksheet Formulas
CellFormula
E1=(1+B1)/A1

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,215,129
Messages
6,123,210
Members
449,090
Latest member
bes000

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