![]() |
|
#16
|
||||
|
||||
|
Is every paragraph in the document an equation? If not, how are the equations to be identified?
How do you want the result to appear? As a Comment or perhaps append '= x' to the end Is there always a minus sign in the equation or is it sometimes just a straight addition task?
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
#17
|
|||
|
|||
|
There are 3 types of paragraphs as described in file A. a paragraph with a minus (red),a paragraph with a plus (green), and a paragraph that is just a sentence (blue). All paragraphs have the sign = followed by a result (which I calculated manually) and which I need to check. and additional text (yellow) can be ignored.
2. In order to facilitate the test I created a new file for the test, and added after the mark = paragraph mark. (File B). So I was left with clean equations for calculation and additional text that is not important to me for the purpose of the test. 3. The situation at the moment is that I go through the document and check with the help of the macro the relevant paragraphs (and ignore the paragraphs that contain the additional text). Is it possible that the software will record the result next to each paragraph and so I will only have to go through the file and make sure that the calculation result of the macro is the same as the calculation I did manually. (File 3). Thanks a lot, |
|
#18
|
||||
|
||||
|
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 |
|
#19
|
|||
|
|||
|
works great, God bless you.
|
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Draft - Retirement Calculator | DJ0691 | Excel | 0 | 01-16-2020 06:56 AM |
Calculator in word
|
Zhibek | Word | 2 | 08-17-2018 12:07 AM |
Result Calculator
|
Raza | Excel Programming | 7 | 01-26-2015 11:35 PM |
| Excel Calculator | Mandusin | Excel | 6 | 12-25-2010 07:34 AM |
| Age Calculator in MS Outlook 2002 SP3 | turns | Outlook | 0 | 06-15-2010 12:26 AM |