View Single Post
 
Old 02-19-2023, 08:40 AM
dopey dopey is offline Windows 10 Office 2021
Novice
 
Join Date: Feb 2023
Posts: 5
dopey is on a distinguished road
Default Combining more than one line of the same item into one line

Hi all,

I hope someone can help me with this. I have some code that looks for a specific symbol in a word document, and then paste that line into a new document. If there are e.g. 3 of the same symbol next to each other, it will copy the same line 3 times, e.g:

Sample list:
pen
book #
desk ###
pencil

It needs to paste the following into the new word document:
book
3 x desk

At the moment, it is writing the word 'desk' three times underneath each other. I have had some help putting the code together, but I am now stuck again on how to streamline it.

I hope it all makes sense.

Code:
This is the code I have so far:
    With oRng.Find
        Do While .Execute(findText:="#")
            oRng.MoveEndWhile Chr(32)
            Set oPara = oRng.Paragraphs(1).Range
            oTarget.Range.InsertAfter (Trim(Replace(oPara.Text, "#", "")))
            oRng.Text = ""
            oRng.Collapse 0
        Loop
    End With
Reply With Quote