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
240 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
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.

786 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