• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • Last Modified:

How to search a column of values in excel and check if value “A” is ever directly preceded by value “B” via a formula resulting in a true or false or via vba?

I have a file that has the data from a work log.  I need to identify if any of the 3 sets of values are listed in order anywhere within cells “E4:E100” ignoring empty cells.  I attached an example file

Test exact order of pair
1st value: Suspended
2nd value: WIP to Open


Suspended    <==========    
                        (Result: True)
WIP to Open <==========

Open to WIP

Open to WIP

WIP to Open
1 Solution
Glenn RayExcel VBA DeveloperCommented:
You can achieve this with a user-defined function (UDF):
Option Explicit
Function Pairs(strFirst As String, strSecond As String, rng As Range) As Boolean
    Dim cl As Object
    Pairs = False
    For Each cl In rng
        If Not (Pairs) Then
            If LCase(cl.Value) = LCase(strFirst) Then
                Pairs = True
            End If
            If LCase(cl.Value) = LCase(strSecond) Then
                Pairs = True
                Exit Function
            ElseIf cl.Value <> "" Then
                Pairs = False
            End If
        End If
    Next cl
End Function

Open in new window

After adding the code to a module in the workbook, you could then insert this function in the green cells.  For example, in cell I3:

The function will return TRUE or FALSE for the specified pair in the first two arguments (cells H3, H4).  The range can be any single column of cells.

Modified example file attached.

kbay808Author Commented:
Awesome!!!  Thank you very much for your help.
Hakan YılmazTechnical Office MEP EngineerCommented:
If you can add a column, you can use SumProduct as in attached file.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now