Find 1st closet value in column

harts

Board Regular
Joined
Apr 5, 2011
Messages
111
Office Version
  1. 365
Platform
  1. Windows
I need to be able to find the first value in column P that is above 89 & below 91 & stop there. The VBA I am using now keeps going & doesn't stop. Because of how I am using it I would like to leave it in VBA & not a formula. Looking for any help. Thanks in advance. Here is what I currently have:

For x1 = 2 To Range("P" & Rows.Count).End(xlUp).Row
If Range("P" & Format(x1) - 1).Value < "91" _
And Range("P" & Format(x1)).Value > "89" _
And Range("P" & Format(x1)).Value > "0" Then
Range("V22") = Range("N" & Format(x1)).Value
End If
Next
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
I'm not sure what you mean by leave it in vba and not a formula.


If this is only likely to occur once then place exit sub at the bottom of the if statement above the line end if
 
Upvote 0
It can reoccur several times after the first time it finds it.
 
Upvote 0
Yes it needs to stop after if finds it the first time.
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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