Forum Discussion
Parsing a text string
- Jun 06, 2021
See the attached workbook. It uses a custom VBA function, so you'll have to allow macros.
Please test thoroughly.
See the attached workbook. It uses a custom VBA function, so you'll have to allow macros.
Please test thoroughly.
- ToriMacJun 15, 2021Copper Contributor
HansVogelaar Amazing!!!! Thank you. How have you done this? I am not familiar with any coding in Excel. Can you tell me how I can see the code and see if I can edit it to do more? This is only the start of what I'd like to do. Wasn't sure if it would be possible. I'd first need to be able to do longer words. Example attached (but could be much longer too)
Thank you so much for this 🙂
- HansVogelaarJun 16, 2021MVP
Press Alt+F11 to activate the Visual Basic Editor.
If you don't see the code immediately, expand Modules in the pane on the left and double-click Module1.
The function currently looks like this:
Function ParseIPA(Word As String) Dim i As Long Dim j As Long Dim c As Range Dim n As Long Dim r(1 To 20) As String i = 1 Do For j = 3 To 1 Step -1 Set c = Worksheets("SymbolsToCSNotationLookup").Range("A2:A53").Find(What:=Mid(Word, i, j), LookAt:=xlWhole) If Not c Is Nothing Then n = n + 1 r(n) = c.Value Exit For End If Next j i = i + Len(r(n)) Loop Until i > Len(Word) ParseIPA = r End Function
The line
Dim r(1 To 20) As String
specifies that the function returns at most 20 characters. If you need more, simply replace 20 with a larger number.
On the spreadsheet, you will have to select the corresponding number of cells in a row, enter the formula and press Ctrl+Shift+Enter if you don't have Excel in Microsoft 365.
- ToriMacJun 16, 2021Copper ContributorThank you !!! I’ll take a good look at this over the next few days. Really appreciate it!
Vicki