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
245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

691 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