Checking for cell value and n number of cells below cell

Luke777

Board Regular
Joined
Aug 10, 2020
Messages
246
Office Version
  1. 365
Platform
  1. Windows
Hi all,

Having trouble getting a bit of code to do what I want.

Basically I'm looking for a way of testing for a particular string in a cell then, if found, test n number of cells underneath that cell for the same string. If they ALL contain the same string THEN do the rest of my code. At any point when testing for the string, if its NO then skip to the Next Cell (makes more sense when you look at my code I think because I've not explained the For Each Cell).

VBA Code:
        For Each cell In Range(Cells(searchRow, 3), Cells(searchRow, lastCol))
            If cell.Value = "yes" Then
                For Y = 1 To tSlots
                    If cell.Offset(Y, 0).Value <> "yes" Then
                        GoTo NextCell
                    ElseIf cell.Offset(Y, 0).Value = "yes" Then
                        If Y = tSlots Then
                            s = s & "," & cell.Address 'this is the part I'm referring to as "The rest of my code" - this is the part that runs if all Y.value = "yes"
                        ElseIf Y <> tSlots Then GoTo NextY
                        End If
                    End If
NextY:
                 Next Y
            End If
NextCell:
        Next cell

I came up with that which combines a few bits from other questions I've asked in the past (if you're one of those folks then thanks!) and yeah, I know its a mess at the moment lol - but I was trying to bodge it a little before tidying it up.

I'll post any additional tidier methods I try in the meantime

Thanks all!
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach a screenshot (not a picture) of your sheet. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitize
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,941
Members
449,094
Latest member
teemeren

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