Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #16  
Old 01-30-2024, 11:51 PM
Guessed's Avatar
Guessed Guessed is offline select until = Windows 10 select until = Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Yacov


Is the intention that the macro needs to work out whether the paragraph has either a - or a + and then duplicates and flips that character?
Is the - paragraph to always be the first paragraph or do you want to add either option below the original paragraph?
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #17  
Old 01-31-2024, 10:17 AM
yacov yacov is offline select until = Windows 10 select until = Office 2016
Competent Performer
select until =
 
Join Date: Oct 2019
Posts: 139
yacov is on a distinguished road
Default

Most of the paragraphs that lack a partner are marked - and I have to copy and change the sign to +. But I also have several hundred paragraphs with a + that I need to copy and turn into a - sign.

It doesn't matter who is up or down - or +. The main thing is that the two paragraphs should be together without another paragraph between them.
thanks.
Reply With Quote
  #18  
Old 01-31-2024, 08:02 PM
Guessed's Avatar
Guessed Guessed is offline select until = Windows 10 select until = Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I think it is useful to maintain some consistency so I've coded this to always do the partner paragraph so that it is minus then plus. This variation will look to see whether the paragraph contains a minus OR a plus and acts accordingly
Code:
Sub DupParaTwoWay()
  Dim aRngPara As Range, aRng As Range, iEqual As Integer, iPlus As Integer, iMinus As Integer
  Set aRngPara = Selection.Paragraphs(1).Range
  iEqual = InStr(aRngPara.Text, "=")
  iPlus = InStr(aRngPara.Text, "+")
  iMinus = InStr(aRngPara.Text, "-")
  If iEqual > 0 Then
    Set aRng = ActiveDocument.Range(aRngPara.Start, aRngPara.Start + iEqual)
    If iPlus > 0 Then
      aRngPara.InsertParagraphBefore
      aRngPara.Collapse Direction:=wdCollapseStart
      aRngPara.FormattedText = aRng.FormattedText
      If Len(aRngPara.Paragraphs(1).Range.Text) = 1 Then aRngPara.Paragraphs(1).Range.Delete
      aRngPara.Characters(iPlus).Text = "-"
    ElseIf iMinus > 0 Then
      aRngPara.InsertParagraphAfter
      aRngPara.Collapse Direction:=wdCollapseEnd
      aRngPara.MoveEnd Unit:=wdCharacter, Count:=-1
      aRngPara.FormattedText = aRng.FormattedText
      aRngPara.Characters(iMinus).Text = "+"
    End If
    aRngPara.Select
  End If
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #19  
Old 01-31-2024, 11:15 PM
yacov yacov is offline select until = Windows 10 select until = Office 2016
Competent Performer
select until =
 
Join Date: Oct 2019
Posts: 139
yacov is on a distinguished road
Default

thanks a lot. work very good
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
select until = Select until last row Marcia Excel Programming 4 08-12-2022 03:54 PM
Select entire text and then de-select certain Headings? tq94 Word 3 02-26-2022 03:47 AM
Select text between 2 yacov Word VBA 2 08-15-2021 10:16 PM
select until = Select a row in a different tab cosmicyes Excel Programming 1 07-09-2018 02:47 AM
select until = How to select row aymanharake Excel Programming 3 02-18-2017 04:09 PM

Other Forums: Access Forums

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


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