View Single Post
 
Old 07-17-2019, 09:13 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

It seems that fellow contributors have been busy while I slept. The original macro didn't work because the search criteria are not as you said. The problem with manuscripts of free text is that they don't always conform to standards so they might not always give the expected results, but based upon your sample I would suggest the following, again bearing in mind that I have not tested it on the Mac version of Word.

It works on the premise that you paste the text into a document and run the macro. The macro adds a table at the top of the page and if the terms are found, it adds them to the first column and highlights them in the text. It then attempts to find the required values associated with them and puts them in the adjacent columns.

As for my own treatment I was diagnosed and treated in an award winning oncology centre (one of the best in Europe) five years ago. All currently appears well though it took a long time to shake off the after effects of the hormone treatment that followed. I finished treatment two years ago. I see my oncologist every six months and I am still alive and well

Code:
Sub Macro1()
Dim vFindText As Variant
Dim oRng As Range
Dim oTable As Table
Dim oCell As Range
Dim oDoc As Document
Dim i As Long, j As Integer
    vFindText = Array("AUA", "SHIM", "PSA", "TURBT", "Frequency")
    Set oDoc = ActiveDocument
    oDoc.Range.InsertParagraphBefore
    Set oRng = oDoc.Range
    oRng.Collapse 1
    Set oTable = oDoc.Tables.Add(oRng, 5, 2)
    For i = 0 To 4
        Set oRng = oDoc.Range
        With oRng.Find
            .ClearFormatting
            .Replacement.ClearFormatting
            Do While .Execute(FindText:=vFindText(i))
                Select Case i
                    Case 0, 1, 2
                        oRng.MoveEndUntil "0123456789"
                        oRng.Collapse 0
                        oRng.MoveEndWhile "0123456789/."
                        Set oCell = oTable.Cell(i + 1, 1).Range
                        oCell.End = oCell.End - 1
                        oCell.Text = vFindText(i)
                        Set oCell = oTable.Cell(i + 1, 2).Range
                        oCell.End = oCell.End - 1
                        oCell.Text = oRng.Text
                    Case Else
                        Set oCell = oTable.Cell(i + 1, 1).Range
                        oCell.End = oCell.End - 1
                        oCell.Text = vFindText(i)
                        Set oCell = oTable.Cell(i + 1, 2).Range
                        oCell.End = oCell.End - 1
                        oCell.Text = True
                End Select
            Loop
        End With
    Next i
lbl_Exit:
    Set oDoc = Nothing
    Set oRng = Nothing
    Set oTable = Nothing
    Set oCell = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote