Hi Everyone,
I'd like to get some guidance on how I can develop a code to compare integer values in different paragraphs, then bold the one that is higher.
I've been working on this for a while and I've got some progress, but the code fails when it reads into the values on the title paragraphs. (See attachment and run code and you'll see what I mean). Another thing to note is that the "range().words" that I use was all I could find in my research to bold the characters I wanted, but I realized that if I have a "Q (cfs)" in the hundreds, it will bold the first number, and I do not want that. I've attached the code and the word document that I'm working with. If anyone could please make this work, or have any comments and feed back, I would greatly appreciate it. I've been learning about macros and VBA for over 2 months and this code in particular will really help me with other vba projects that I want to get started on.
PS: I am a newb and I realize that my coding may be unprofessional or weird looking so please excuse me. I will get better with your help.
Thank you
Sub Elevation_bold_beta1()
Dim MyDoc As Document
Dim parajx As Paragraph
Dim paraq1 As Paragraph
Dim paraq2 As Paragraph
Dim a As String
Dim b As String
Dim e1 As Integer
Dim e2 As Integer
Set MyDoc = ActiveDocument
For p = 1 To MyDoc.Paragraphs.Count
Set parajx = MyDoc.Paragraphs(p)
Set paraq2 = MyDoc.Paragraphs(p + 2)
Set para = MyDoc.Paragraphs(p + 14)
b = Mid(paraq2, 41, 9)
Z = Mid(parajx, 2, 9)
If Z = "JUNCT STR" Then
Set paraq1 = MyDoc.Paragraphs(p - 2)
a = Mid(paraq1, 41, 9)
If a = b Then
Else
e2 = Mid(paraq2, 32, 8)
e1 = Mid(paraq1, 32, 8)
If e1 > e2 Then
ActiveDocument.Paragraphs(p - 2).Range.Words(11).Select
Selection.Range.Bold = True
ActiveDocument.Paragraphs(p - 2).Range.Words(12).Select
Selection.Range.Bold = True
ActiveDocument.Paragraphs(p - 2).Range.Words(13).Select
Selection.Range.Bold = True
Else
If e2 > e1 Then
ActiveDocument.Paragraphs(p + 2).Range.Words(11).Select
Selection.Range.Bold = True
ActiveDocument.Paragraphs(p + 2).Range.Words(12).Select
Selection.Range.Bold = True
ActiveDocument.Paragraphs(p + 2).Range.Words(13).Select
Selection.Range.Bold = True
End If
End If
End If
End If
Next
End Sub
Display More