Find the first positive number after deducting from a range of numbers VBA

Sotos13

New Member
Joined
Mar 8, 2019
Messages
42
Hi all
I have to find a way to solve this problem. I have a column with different numbers for example x1 x2 x3..x1000, and a specific range of 125 y1 y2 y3.. y125 numbers.
i want to find which x number is closest to a y number. So i was thinking to do y1-x1= and y2-x1= and y3- x1= and so on. the smallest positive number will be my correct answer. So in the below example the answer is 4848 and i want vba to bring me back in a specific column the Y number which in this case is 300000. Feel free to ask anything...waiting for some suggestions.


YXY-X
282000295152-13152
288000-7152
288000-7152
3000004848
3008005648

<colgroup><col width="64" span="3" style="width:48pt"> </colgroup><tbody>
</tbody>
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Great Dante!!! It works with one exception though..it reaches up to the point where you have numbers in column A. If you have more numbers in Column B it doesn't:) calculate them
see below
78400097014100800
823200254661,8256000
86240072760,575200
901600286440288000
940800139536144000
980000138240144000
184320
137484
228000

<colgroup><col width="64" span="3" style="width:48pt"> </colgroup><tbody>
</tbody>
 
Upvote 0
Great Dante!!! It works with one exception though..it reaches up to the point where you have numbers in column A. If you have more numbers in Column B it doesn't:) calculate them
see below
78400097014100800
823200254661,8256000
86240072760,575200
901600286440288000
940800139536144000
980000138240144000
184320
137484
228000

<tbody>
</tbody>


They are small details that I do not know, butTry this:

Code:
Sub FormulaXY_2()
    Dim lr As Long, lb As Long, i As Long
    lr = Range("A" & Rows.Count).End(xlUp).Row
    lb = Range("B" & Rows.Count).End(xlUp).Row
    For i = 2 To lb
        With Range("C" & i)
            .FormulaArray = "=INDEX($A$1:$A$" & lr & ",MIN(IF($A$2:$A$" & lr & "-B" & i & ">0,ROW($A$2:$A$" & lr & "))))"
            .Value = .Value
        End With
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

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