+ Reply to Thread
Results 1 to 4 of 4

Retun the value of a cell above a specific pattern

Hybrid View

  1. #1
    Registered User
    Join Date
    05-08-2010
    Location
    AZ
    MS-Off Ver
    Excel 2007
    Posts
    49

    Retun the value of a cell above a specific pattern

    Hi all,

    I was helped in the past with the script below, but I am having trouble altering it to work for another task. Essentially I want everytime strings with the phrase, "positive Match" and "2_Not List" appear in consecutive cells, I want to return the Record ID.

    For the sample data attached the results would end up in A1 of the same sheet as

    123456789
    01234567

    Set ws1 = Sheets("Sheet1Sample Data.xlsx")
    Dim RID As String
        Dim X As Integer
        X = 1
        LastRow = Cells(Rows.Count, "A").End(xlUp).Row
        For Each c In Range("A1:A" & LastRow)
            If InStr(1, c.Value, "RecordID") > 0 Then
            RID = c.Value
            For Each Y In Range("A" & (c.Row + 1) & ":A" & LastRow)
                If InStr(1, Y.Value, "Positive Match") > 0 Then
                    Cells(X, 2).Value = RID
                    X = X + 1
                    Exit For
                End If
                If InStr(1, Y.Value, "RecordID") > 0 Then
                    Exit For
                End If
            Next
            End If
        Next
    Columns(1).Delete
    Thank you in advance!

  2. #2
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,879

    Re: Retun the value of a cell above a specific pattern

    Hi,

    Please see the new file attached.

    On purpose I've extracted the RecordsID on B Column so that you can compare it with the original data
    Attached Files Attached Files
    Cheers!
    Deep Dave

  3. #3
    Registered User
    Join Date
    05-08-2010
    Location
    AZ
    MS-Off Ver
    Excel 2007
    Posts
    49

    Re: Retun the value of a cell above a specific pattern

    Thank you! That worked perfectly!

  4. #4
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,879

    Re: Retun the value of a cell above a specific pattern

    Glad! Please mark the thread as solved..

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Copy down hypertext cell range pattern & cell reference formula pattern
    By Underexcelling in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-10-2014, 03:23 AM
  2. [SOLVED] Remove pattern from cells only if another cell has a specific selection from dropdown list
    By mook25 in forum Excel Programming / VBA / Macros
    Replies: 25
    Last Post: 08-16-2013, 07:32 AM
  3. Replies: 12
    Last Post: 03-02-2009, 04:36 PM
  4. [SOLVED] How do I set the tab stops in a specific cell pattern?
    By PE in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-26-2006, 04:00 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1