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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

737 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