jeudi 7 mai 2020

Searching for a specific text in a column within an If statement

I am trying to find a specific text within a column using an if statement (shown below). Currently I'm searching each cell individually but would like to be able to shorten that code to search all of them.

If InStr(Sheet2.Range("R" & CustRow).Value, "Cradle") > 0 Then
    If InStr(Sheet2.Range("R5"), "PFC") Or
    If InStr(Sheet2.Range("R6"), "PFC") Or
    If InStr(Sheet2.Range("R7"), "PFC") Or
    If InStr(Sheet2.Range("R8"), "PFC") Or
    If InStr(Sheet2.Range("R9"), "PFC") Or
    If InStr(Sheet2.Range("R10"), "PFC") Or
    If InStr(Sheet2.Range("R11"), "PFC") Or
    ....
 Then
    ThisWorkbook.FollowHyperlink PdfTemplate16
Else: ThisWorkbook.FollowHyperlink PDFTemplateFile17
Application.Wait Now + 0.00001
End If

I would like to be able to search from row 5 to row 44 but really don't want to have that repetitive code in there.

Thank you for any help.

Aucun commentaire:

Enregistrer un commentaire