Log in

View Full Version : [SOLVED:] Move Paragraphs Back Up 1 Line



dj44
06-20-2017, 08:17 AM
Folks,

good tuesday,

I am trying to move my paragraphs up but only if it has a square bracket at the end

I got started but I cant seem to move it up




Sub MoveUp()


Dim oPar As Paragraph
Dim oRng As Range
For Each oPar In ActiveDocument.Range.Paragraphs


If InStr(oPar.Range.Characters.Last, "[") > 0 Then

Set oRng = oPar.Range
oRng.Move wdCharacter, -2

'oRng.Next.Paragraphs

oRng.InsertBefore " " & Left(oPar.Range.Text, Len(oPar.Range.Text) - 1)



End If


Next
lbl_Exit:
Exit Sub


End Sub


and an image for illustartive purposes to see what im trying to do


19546

I tried to delete characters from the end but that didnt work

thank you for your help

gmaxey
06-20-2017, 03:01 PM
Sub MoveUp()
Dim oPar As Paragraph
Dim oRng As Range
Dim lngIndex As Long
For lngIndex = ActiveDocument.Range.Paragraphs.Count To 2 Step -1
If ActiveDocument.Range.Paragraphs(lngIndex - 1).Range.Characters.Last.Previous = "[" Then
ActiveDocument.Range.Paragraphs(lngIndex - 1).Range.Characters.Last.Delete
End If
Next lngIndex
lbl_Exit:
Exit Sub
End Sub

dj44
06-20-2017, 03:37 PM
Hello Greg,

nice to see hope you are well


Now previously one time I had the same situation but it was a word and I was successful in moving that up
but the minute I tried to move a character up it just wouldn't budge and I tried everything

I also tried using some regular expressions well that was a fail.

There have been some mysterious characters appearing in my word :think:

- i discovered they were non breaking space which i never knew before any how

But im very happy becuase that square bracket was unsightly in the worng place
and i had to manually move my paragraphs and my carpol tunnel was very bad this week

So thank you

And good evening

:yes