Forum Discussion
Mistermonopoly
May 20, 2024Copper Contributor
Find text within a comma delimitated string
I have a column with comma delimitated data string: 1) abc 2) abc,xyz 3) idf,abc 4) pdq,abc,xyz 5) mabc,xyz 6) idf,abcd I am trying to show any data set with ID abc in it and i can pick out...
- May 20, 2024
=OR(TEXTSPLIT(A1,",")="abc")
Mistermonopoly
May 20, 2024Copper Contributor
NikolinoDE that works for find the ID between the commas which I was doing with a find “,abc,” function already. I am struggling more with instances 5 & 6 where they fall either in front “xabc” or at the end “abcx”.
NikolinoDE
May 20, 2024Gold Contributor
Try with a Custom Function in VBA, you can write a custom function to check if "abc" appears as a standalone item in a comma-delimited string, regardless of its position within the string. Below is a VBA function that you can use:
Vba Code (find in insert file):
Function FindABC(ByVal inputString As String) As String
Dim dataArray() As String
Dim element As Variant
' Split the input string into an array using comma as delimiter
dataArray = Split(inputString, ",")
' Loop through each element in the array
For Each element In dataArray
' Check if "abc" is found in the element
If InStr(1, Trim(element), "abc", vbTextCompare) > 0 Then
' If "abc" is found, return "Yes" and exit the function
FindABC = "Yes"
Exit Function
End If
Next element
' If "abc" is not found in any element, return "No"
FindABC = "No"
End Function
Steps to Implement:
- Press Alt + F11 to open the Visual Basic for Applications (VBA) editor.
- Go to Insert > Module to insert a new module.
- Copy and paste the above VBA function into the module.
- Close the VBA editor.
- Now, you can use this custom function FindABC in your Excel sheet.
In Excel, in column C, enter the formula =FindABC(A2) where A2 is the cell containing your data. Then, drag the formula down for all rows to check each cell in column A.
This VBA function will correctly identify instances where "abc" appears.
- MistermonopolyMay 20, 2024Copper ContributorThank you I may end up trying this through VBA as a last resort. I was really trying to stick to formulas so the rest of my team could work with the sheet on the fly.