Forum Discussion
Obtain data from a cell with lots of paragraphs
- Apr 09, 2022
If you want the function to be available in all workbooks, store it in a module in an add-in or in your personal macro workbook PERSONAL.XLSB.
Is the attached version better?
See the attached version, now a macro-enabled workbook.
Thank you so much for the function! you're a god.
however, I need to tweak it a bit.
so the UC, was for the student Amy.
when Hamlet used the word "my" in his sentence, I needed to know what Horatio said.
not what were the words before "my" in the same sentence hamlet uttered.
For those where "my" is in the sentence the very first person said. Since there is no previous person, it can return a blank.
If possible, to make the output like ": Where, my lord?HAMLET:"
i.e, Searching from the nearest ":" to the next nearest preceding ":".
or ideally HORATIO: Where, my lord? (but given how dynamic the ideal output is, just Searching from the nearest ":" to the next nearest preceding ":". as stated above is more than enough.
What changes do I need to make in this code you've provided. (also, how to get this copy of this function permanently on all my workbooks?) TYSM! you're so awesome at this!
codeOption Explicit
Function ExtractParts(Txt As String, Keyword As String) As String
Dim strLines() As String
Dim varLine As Variant
Dim i As Long
Dim p1 As Long
Dim p2 As Long
Dim n As Long
Dim strReturn() As String
strLines = Split(Txt, vbLf)
For Each varLine In strLines
p2 = InStr(1, varLine, Keyword, vbTextCompare)
If p2 > 0 Then
p1 = InStr(1, varLine, ":")
n = n + 1
ReDim Preserve strReturn(1 To n)
strReturn(n) = Trim(Mid(varLine, p1 + 1, p2 - p1 - 1))
End If
Next varLine
ExtractParts = Join(strReturn, vbLf)
End Function
- HansVogelaarApr 09, 2022MVP
If you want the function to be available in all workbooks, store it in a module in an add-in or in your personal macro workbook PERSONAL.XLSB.
Is the attached version better?
- SandeeepApr 10, 2022Copper ContributorUpdate, I got my old macros to work.
But on your file now it shows Ambiguous name detected: ExtractParts- SandeeepApr 10, 2022Copper ContributorUpdate, so I copied it to my PERSONAL.XLSB but whenever I open a new csv file or xlsx file.
The function does not work, and throws a #NAME? issue.
Anything I need to do so this function =ExtractParts(transcriptcell,absolute_cell_Value_for_keyword) works on my csv & xslx files?
- SandeeepApr 10, 2022Copper ContributorPlease help.
Update, I somehow got it to work on the other workbook. but now all my old macros vanished and idky - SandeeepApr 10, 2022Copper Contributor
OMG OMG OMG OMG!!!!! This is exactly what I needed!!!!
However, I'm facing a problem on how to save what you've made to all my excel workbooks from now on.
I copied my columns to your text(dot)xslm files. And it works perfectly.
Now how do I add this to my other workbooks.
Tried googling the procedure, and I exported the module, and tried importing it. didn't work.
and tried random stuff on my other workbooks. didn't work either.
unsure what keywords to google to get the answer. I've googled "how to save a custom excel function to my other workbooks" and tried those stuff. perhaps I'm doing the procedure wrong.
THANK YOU SO MUCH!!!! this helps me so immensely.