Update using a tab as a compliance indicator
Assuming Tab is an appropriate indicator, you can do the following:
Sub ExtractElement() ' column 4 and row 6 contains the text "take 0.5 Tab by mouth 2 times daily" s = Cells(6, 4).Value ' split text into array for each space sAr = Split(s, " ") ' iterate over each element of array For i = 0 To UBound(sAr) - 1 ' if the array element "Tab" is reached If sAr(i) = "Tab" Then ' write the previous array element into the next column Cells(6, 5).Value = sAr(i-1) End If Next End Sub
Beware that each word is truly separated by a β.β I copied your text and noticed that βTab byβ is not separated.
Sub ExtractCharCode() s = Cells(7, 4).Value For i = 1 To Len(s) Cells(i, 8).Value = Mid(s, i, 1) Cells(i, 9).Value = Asc(Mid(s, i, 1)) Next End Sub
Instead of passing a range to a function from matzone, I would only pass the value and add a trimmer to it
Public Function TakeBeforeTab2(s As String) As String s = Mid(s, 1, InStr(UCase(s), "TAB") - 1) TakeBeforeTab2 = Trim(Mid(s, InStr(s, " ") + 1)) End Function
source share