Find a row that matches multiple conditions with a given row

Alex126

New Member
Joined
Mar 4, 2023
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello.

Table A1:Hx (x is a small number, so I can just set it to 50; ideally I'd like it so it only checks up to the last non-empty row) with a bunch of numbers.
I want a VBA that checks if the values in a certain row have a certain relation with values of any of the subsequent rows. It's a simple "loop/next" thing, but I'm just about to throw my computer out the window trying to figure out how. This is the one I have written so far:

VBA Code:
Dim lr As Long
Dim i As Long, x As Long

lr = Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To 50
x = i + 1

If Cells(i, 5).Value > Cells(x, 5).Value And Cells(i, 7).Value < Cells(x, 7).Value And Cells(i, 6).Value > Cells(x, 6).Value And Cells(i, 8).Value < Cells(x, 8).Value Then
Cells(i, 15).Value = "found"

End If
Next i


What I need is something like "Else x=x+1, then do until the condition is true". Can't figure it out. Right now the script, I think, can only give a "true" value if the row immediately after the one examined meets the condition, but I can't make it "go find if another row further down below meets the condition" before moving on to checking a match for the next row.
 
Last edited by a moderator:

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Welcome to the MrExcel board!

For vba, please use the available vba code tags, not the Quote tags. My signature block below has more information. I have swapped the tags for you this time. :)
 
Upvote 0

Forum statistics

Threads
1,224,830
Messages
6,181,225
Members
453,025
Latest member
Hannah_Pham93

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