Thread: select until =
View Single Post
 
Old 01-30-2024, 04:18 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
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 would do this with string functions to get the relevant positions of the - and the = characters. I don't see how the find makes it faster.
Code:
Sub DupPara()
  Dim aRngPara As Range, aRng As Range, iEqual As Integer, iPlus As Integer
  Set aRngPara = Selection.Paragraphs(1).Range
  iEqual = InStr(aRngPara.Text, "=")
  iPlus = InStr(aRngPara.Text, "-")
  If iEqual > 0 Then
    Set aRng = ActiveDocument.Range(aRngPara.Start, aRngPara.Start + iEqual)
    aRngPara.InsertAfter vbCr
    aRngPara.Collapse Direction:=wdCollapseEnd
    aRngPara.MoveEnd Unit:=wdCharacter, Count:=-1
    aRngPara.FormattedText = aRng.FormattedText
    aRngPara.Characters(iPlus).Text = "+"
  End If
End Sub
I assume it would be logical to also build in the MyCalculator function as well but I can't work out what the user has selected before running that code.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote