VBA for finding a value in a column from a set target value

earendil

New Member
Joined
Jun 29, 2012
Messages
1
Target
Percent
Value
Answer
0.9
1
20
? = Average between values for 0.91 & 0.87
0.91
40
0.87
80
0.81
10

<TBODY>
</TBODY>
Im looking to put in a value in a target cell and wanting to search for that target value in a column. Never falls directly on target value so need to take average of the greater and less than value and output that to answer cell.
 
Last edited:

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Here is some quick dode that solves the example...

Code:
Sub Process()
    Dim Wb As Workbook
    Dim trg As Single
    Dim RowNo As Long
    
    Dim Ws As Worksheet
    
    Set Wb = ThisWorkbook
    Set Ws = Wb.Worksheets("Sheet1")
    
    trg = Ws.Range("A2")
    
    For RowNo = 2 To 5
        
        If Ws.Cells(RowNo, "B") < trg Then
            Ws.Cells(2, "D") = (Ws.Cells(RowNo - 1, "B") + Ws.Cells(RowNo, "B")) / 2
            Exit Sub
        End If
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,524
Messages
6,055,907
Members
444,832
Latest member
bgunnett8

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