Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-28-2018, 05:17 AM
gmayor's Avatar
gmayor gmayor is offline How to move a line to another line that starts with a chain selected in the 1st one? Windows 10 How to move a line to another line that starts with a chain selected in the 1st one? Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
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 ofgmayor has much to be proud of
Default

The following macro will find the next paragraph that begins with the selected text and will insert the paragraph that contains the selected text before it. It assumes that at least two words are selected. You can change that as appropriate. http://www.gmayor.com/installing_macro.htm



Code:
Sub Macro1()
'Graham Mayor - http://www.gmayor.com - Last updated - 28 Oct 2018 

 Dim oRng As Range, oSel As Range
    Set oSel = Selection.Range
    If oSel.Words.Count > 2 Then
        Set oRng = ActiveDocument.Range
        oRng.Start = oSel.Paragraphs(1).Range.End
        With oRng.Find
            Do While .Execute(oSel)
                If oRng.Start = oRng.Paragraphs(1).Range.Start Then
                    oRng.Collapse 1
                    oRng.FormattedText = oSel.Paragraphs(1).Range.FormattedText
                    oSel.Paragraphs(1).Range.Delete
                    Exit Do
                End If
                oRng.Collapse 0
            Loop
        End With
    End If
lbl_Exit:
    Set oRng = Nothing
    Set oSel = 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
  #2  
Old 10-28-2018, 05:44 AM
gloub gloub is offline How to move a line to another line that starts with a chain selected in the 1st one? Windows 7 64bit How to move a line to another line that starts with a chain selected in the 1st one? Office 2003
Novice
How to move a line to another line that starts with a chain selected in the 1st one?
 
Join Date: Feb 2018
Location: Paris, France
Posts: 29
gloub is on a distinguished road
Default

WOW !!!!

That's great, thanks : it's 99% what I was dreaming of !

The last thing is : I need the macro to work on a chain, no matter whether it is 3 characters or a whole sentence (typically I would select 4 or 5 characters).
Could you help me do this, please ?

THANKS !!!!!!!
Reply With Quote
  #3  
Old 10-28-2018, 06:09 AM
gloub gloub is offline How to move a line to another line that starts with a chain selected in the 1st one? Windows 7 64bit How to move a line to another line that starts with a chain selected in the 1st one? Office 2003
Novice
How to move a line to another line that starts with a chain selected in the 1st one?
 
Join Date: Feb 2018
Location: Paris, France
Posts: 29
gloub is on a distinguished road
Default

OK, I've just changed
Code:
If oSel.Words.Count > 2 Then
to
Code:
If oSel.Words.Count > 1 Then
and it seems to work perfectely.
Am I right ?
Reply With Quote
  #4  
Old 10-28-2018, 06:25 AM
gloub gloub is offline How to move a line to another line that starts with a chain selected in the 1st one? Windows 7 64bit How to move a line to another line that starts with a chain selected in the 1st one? Office 2003
Novice
How to move a line to another line that starts with a chain selected in the 1st one?
 
Join Date: Feb 2018
Location: Paris, France
Posts: 29
gloub is on a distinguished road
Default

After further testing, this small change is not enough to make the macro work ie on a 3 characters chain...
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to move a line to another line that starts with a chain selected in the 1st one? Document starts to red line spaces and formatting appears on right side Richtriebe Word 2 03-23-2017 11:53 AM
Bold each line of text that starts with a recurring symbol qubie Word 6 08-26-2016 07:10 AM
Lock line so text does not move to next line saundrals Word 2 06-19-2014 03:59 PM
How to move a line to another line that starts with a chain selected in the 1st one? Identify certain text and move all phrases containing it down a line Chayes Word VBA 2 11-26-2013 01:16 PM
How to move a line to another line that starts with a chain selected in the 1st one? How to give line numbering to only selected text? garlapati Word 5 04-04-2011 02:05 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:16 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft