Searching anything within a cell and it exists in a column

apexRaiden

New Member
Joined
Oct 7, 2021
Messages
15
Office Version
  1. 365
Platform
  1. Windows
Good day,

I am trying to formulate a process where I can do a lookup or a search of ANYTHING within a cell and see if it exists in a column of entries.
The cell in question has a few lines of data but specifically has a line of data that could either have 1 entry or multiple entries that are separated by commas. I am trying to find a way to look for THOSE entries are within the column of data/entries to see if they match/exist. My end goal is to then say that if this does exist in column, then populate the rest of this entries details that are on another sheet. Almost as a IF TRUE THEN = 2ndSheet CELL DATA.

I know this formula doesn't work, but I hope it helps in the sense of explanation
=vlookup("*"&B2&"*",A:A,1,FALSE)

Again, I understand that this doesn't work, but I am just trying to help paint a picture of what im trying to obtain.
Is ANYTHING within THIS CELL over here in this column of entries?

Thank you!
 
OK, I think I have come up with VBA code that will work regardless of whether or not you have soft carriage returns in column B.
Paste this code in a VBA module in your workbook, and run it on your data, and it should populate column C according to your specifications.
VBA Code:
Sub PopulateColumnC()

    Dim lrA As Long
    Dim lrB As Long
    Dim rngA As Range
    Dim r As Long
    Dim str1 As String
    Dim arr1() As String
    Dim arr2() As String
    Dim i As Long
    Dim str2 As String
    
    Application.ScreenUpdating = False
    
'   Find last row with data in columns A and B
    lrA = Cells(Rows.Count, "A").End(xlUp).Row
    lrB = Cells(Rows.Count, "B").End(xlUp).Row
    
'   Set range for column A
    Set rngA = Range("A2:A" & lrA)
    
'   Loop through all rows in column B starting at row 2
    For r = 2 To lrB
'       Set value in column C to FALSE, initially
        Cells(r, "C") = "FALSE"
'       Get value from column B
        str1 = Cells(r, "B")
'       Remove any carriage returns or line feeds from string
        str1 = Replace(str1, vbCr, "")
        str1 = Replace(str1, vbLf, "")
        str1 = Replace(str1, vbCrLf, "")
'       Split data at colon
        arr1 = Split(str1, ":")
'       Split data at commas
        arr2 = Split(Trim(arr1(1)), ",")
'       Loop through all values
        For i = LBound(arr2) To UBound(arr2)
'           Get individual value
            str2 = Trim(arr2(i))
'           Check to see if value is found in column 1
            If Application.WorksheetFunction.CountIf(rngA, str2) > 0 Then
'               If it is, set column C to TRUE and exit loop
                Cells(r, "C") = "TRUE"
                Exit For
            End If
        Next i
    Next r
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
OK, I think I have come up with VBA code that will work regardless of whether or not you have soft carriage returns in column B.
Paste this code in a VBA module in your workbook, and run it on your data, and it should populate column C according to your specifications.
VBA Code:
Sub PopulateColumnC()

    Dim lrA As Long
    Dim lrB As Long
    Dim rngA As Range
    Dim r As Long
    Dim str1 As String
    Dim arr1() As String
    Dim arr2() As String
    Dim i As Long
    Dim str2 As String
   
    Application.ScreenUpdating = False
   
'   Find last row with data in columns A and B
    lrA = Cells(Rows.Count, "A").End(xlUp).Row
    lrB = Cells(Rows.Count, "B").End(xlUp).Row
   
'   Set range for column A
    Set rngA = Range("A2:A" & lrA)
   
'   Loop through all rows in column B starting at row 2
    For r = 2 To lrB
'       Set value in column C to FALSE, initially
        Cells(r, "C") = "FALSE"
'       Get value from column B
        str1 = Cells(r, "B")
'       Remove any carriage returns or line feeds from string
        str1 = Replace(str1, vbCr, "")
        str1 = Replace(str1, vbLf, "")
        str1 = Replace(str1, vbCrLf, "")
'       Split data at colon
        arr1 = Split(str1, ":")
'       Split data at commas
        arr2 = Split(Trim(arr1(1)), ",")
'       Loop through all values
        For i = LBound(arr2) To UBound(arr2)
'           Get individual value
            str2 = Trim(arr2(i))
'           Check to see if value is found in column 1
            If Application.WorksheetFunction.CountIf(rngA, str2) > 0 Then
'               If it is, set column C to TRUE and exit loop
                Cells(r, "C") = "TRUE"
                Exit For
            End If
        Next i
    Next r
   
    Application.ScreenUpdating = True
   
End Sub
So i ran the VBA on a macro enabled sheet and it populated the FALSE results but didnt seem to get to the "TRUE" portion of the code.

Here a more "realistic" set of data that hopefully gives something else that I'm missing? I have a feeling there are hidden characters getting in the way...


Test CISA KEV Lookup.xlsm
AB
1IDsNames
2CVE-2022-417OS Plugin ID: 1 CVE(s): CVE-2021-269
3CVE-2021-22OS Plugin ID: 16 CVE(s): CVE-2022-12
4CVE-2021-269OS Plugin ID: 12 CVE(s): CVE-2022-83, CVE-2022-417, CVE-2022-45
5CVE-2021-2103OS Plugin ID: 15 CVE(s): CVE-2022-207
6CVE-2021-7OS Plugin ID: 17 CVE(s): CVE-2022-38, CVE-2022-7
7CVE-2022-2OS Plugin ID: 11 CVE(s): CVE-2022-2
8CVE-2022-12OS Plugin ID: 19 CVE(s): CVE-2022-39
Sheet1
 
Upvote 0

Forum statistics

Threads
1,214,912
Messages
6,122,204
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top