Forum Discussion
Sandeeep
Apr 09, 2022Copper Contributor
Obtain data from a cell with lots of paragraphs
Cool, So I have multiple questions I need help with regarding formulas and macros. ok, So I have a cell that contains paragraphs of text. Imagine I'm a teacher, and each student gave multiple par...
- 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?
HansVogelaar
Apr 09, 2022MVP
I'll give you 1. and 2.
Sandeeep
Apr 09, 2022Copper Contributor
TYSM, the text.xlsx file has the exact similar kind of data I have, (mine is 500-100 everyday) and I got like 9 such per day.
I had the solution for 1. I'm so thankful for the Frequency thing. It's exactly what I needed.
ty ty ty ty
Any ideas for 3? I've been googling for 2weeks with random stuff, but none seem to be exactly what I need. Would love for getting a formula for that!
I can do 4. record macro myself, so that's fine. Hoping someone can solve 3. for me
I had the solution for 1. I'm so thankful for the Frequency thing. It's exactly what I needed.
ty ty ty ty
Any ideas for 3? I've been googling for 2weeks with random stuff, but none seem to be exactly what I need. Would love for getting a formula for that!
I can do 4. record macro myself, so that's fine. Hoping someone can solve 3. for me
- HansVogelaarApr 09, 2022MVP
See the attached version, now a macro-enabled workbook.
- SandeeepApr 09, 2022Copper Contributor
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!
code
Option 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?