Solved

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?

Posted on 2014-12-04
3
238 Views
Last Modified: 2014-12-04
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

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

Dataset:

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

Open to WIP

Suspended
Open to WIP

WIP to Open
Example.xlsx
0
Comment
Question by:kbay808
3 Comments
 
LVL 27

Accepted Solution

by:
Glenn Ray earned 500 total points
ID: 40482244
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
        Else
            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:
=pairs(H3,H4,$E$4:$E$100)

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.

Regards,
-Glenn
EE-Q28574834.xlsm
0
 

Author Closing Comment

by:kbay808
ID: 40482277
Awesome!!!  Thank you very much for your help.
0
 
LVL 5

Expert Comment

by:Hakan Yılmaz
ID: 40482282
If you can add a column, you can use SumProduct as in attached file.
Example1.xlsx
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now