View Single Post
 
Old 07-19-2021, 12:32 AM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,164
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

Assuming the paragraphs you want calculated all end with an equal sign, this will add the value after that character.
Code:
Sub MyCalculatorAll()
  Dim aChar As Variant, aRng As Range, iTotal As Long, bFlip As Boolean, aPara As Paragraph
  
  For Each aPara In ActiveDocument.Paragraphs
    Set aRng = aPara.Range
    aRng.End = aRng.End - 1
    'aRng.Select   'activate this line to see the progress or testing
    If aRng.Characters.Last = "=" Then
      iTotal = 0
      bFlip = False
      For Each aChar In aRng.Characters
        Select Case AscW(aChar)
          Case 1488 To 1497: iTotal = iTotal + AscW(aChar) - 1487
          Case 1498, 1499: iTotal = iTotal + 20
          Case 1500: iTotal = iTotal + 30
          Case 1501, 1502: iTotal = iTotal + 40
          Case 1503, 1504: iTotal = iTotal + 50
          Case 1505: iTotal = iTotal + 60
          Case 1506: iTotal = iTotal + 70
          Case 1507, 1508: iTotal = iTotal + 80
          Case 1509, 1510: iTotal = iTotal + 90
          Case 1511: iTotal = iTotal + 100
          Case 1512: iTotal = iTotal + 200
          Case 1513: iTotal = iTotal + 300
          Case 1514: iTotal = iTotal + 400
          Case 45: iTotal = iTotal * -1: bFlip = True 'a minus sign
        End Select
      Next aChar
      If bFlip Then iTotal = iTotal * -1
      aRng.InsertAfter iTotal
    End If
  Next aPara
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote