excel5028000
New Member
- Joined
- Mar 5, 2020
- Messages
- 9
- Office Version
- 365
- 2016
- Platform
- Windows
Hi MrExcel and Everyone,~ I hope you're all doing great, fine and well at this time!
I need help with the Instr function, or please let me know if a better function exists in Excel/VBA, that would work almost like fuzzy logic to look at data in a cell, and determine if a specific string is present. The Instr function requires a starting position of character in order to work; even though it's supposed to be optional.
Instr( [start], string, substring, [compare] )
However my dilemma is what if you don't know the starting position. What if the position can be any where? This is best illustrated by sample data below. On column A, I have some dirty data that gets spitted out from a bank let's say. (Image below is after running macro with output on column B).
Over time, I learned to create a cross reference table visually searching the bank data for a specific string, and if that string exists then I would pull the clean data or in this example the Legal Name of Entity, its equivalent.
Here's a simple two loop VBA code I am trying. But if you notice, it only works if the [start] position of the dirty data is one.
Do I do vbBinaryCompare? or vbTextCompare? I tried both.
Come to think of it now, I suppose we could do a process using LEN(A2) find length of each cell on column A, then create a loop changing the starting position each time ==> from 1 to value of the LEN output. But I am not there yet. I am hoping someone knows; please even employ xlookup or any function that will do the job.
Here's actual text data for copy pasting.
Thank you very much!!!
I need help with the Instr function, or please let me know if a better function exists in Excel/VBA, that would work almost like fuzzy logic to look at data in a cell, and determine if a specific string is present. The Instr function requires a starting position of character in order to work; even though it's supposed to be optional.
Instr( [start], string, substring, [compare] )
However my dilemma is what if you don't know the starting position. What if the position can be any where? This is best illustrated by sample data below. On column A, I have some dirty data that gets spitted out from a bank let's say. (Image below is after running macro with output on column B).
Over time, I learned to create a cross reference table visually searching the bank data for a specific string, and if that string exists then I would pull the clean data or in this example the Legal Name of Entity, its equivalent.
Here's a simple two loop VBA code I am trying. But if you notice, it only works if the [start] position of the dirty data is one.
VBA Code:
Sub Test()
For II = 2 To 12
For JJ = 2 To 5
If InStr(1, Cells(II, 1), Cells(JJ, 7), vbBinaryCompare) = 1 Then
Let Cells(II, 2) = Cells(JJ, 8)
GoTo 550
End If
Next JJ
550
Next II
End Sub
Do I do vbBinaryCompare? or vbTextCompare? I tried both.
VBA Code:
I tried => If InStr(1, Cells(II, 1), "*" & Cells(JJ, 7) & "*", vbTextCompare) = 1 Then
Come to think of it now, I suppose we could do a process using LEN(A2) find length of each cell on column A, then create a loop changing the starting position each time ==> from 1 to value of the LEN output. But I am not there yet. I am hoping someone knows; please even employ xlookup or any function that will do the job.
Here's actual text data for copy pasting.
DIRTY_BANK_DATA_DOWNLOAD | Lookup_String | LEGAL_NAME_ENTITY | |||||
0121D ,8760655567,Champion Energy ,Primary Groups, | Champion | Champion Energy Commerical Company | |||||
ACHOUT ,9062765001,VOXX PAY,Primary Groups, | VOX | Voxx International Company | |||||
EDI PAYMNT,6113666506,DYNEGY,Primary Groups, | DYNEGY | Dynegy Energy Company | |||||
EDI PAYMNT,1813015683,NEW YORK G&P LLC,Primary Groups, | TXU | TXU Energy | |||||
McCoy Electric BILL 0201902700 | |||||||
TXU ENERGY TXU ACH 10015265514 | TXU Energy | ||||||
Champion Energy 0121D | Champion Energy Commerical Company | ||||||
Sprint Payment 033020 757113004BDE9S | |||||||
OXY Refinery PAYMENT 200401 0000786255 | |||||||
ACHOUT ,9062762145,VOXX PAY,Primary Groups, | |||||||
TXU ENERGY TXU ACH 106942628290 | TXU Energy |
Thank you very much!!!