Comparing Integer values in paragraphs and bold higher value

  • 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



  • Re: Comparing Integer values in paragraphs and bold higher value


    Hi mbecerra24


    Welcome to the forum


    Its a little unclear what you are trying to do. You have to remember that no one has the same affinity to your work as you do.


    is it where the JUNCT STR values cross over a page title or are the JUNCT STR only then next two values?

  • Re: Comparing Integer values in paragraphs and bold higher value


    heaps of ways to deal with and find the charactors to bold

    Code
    Debug.Print paraq1.Range.Text
               Debug.Print paraq2.Range.Characters.Count
      
               Debug.Print paraq1.Range.Words.Count
     
                Debug.Print paraq2.Range.Words.Item(1)
                 Debug.Print paraq2.Range.Words.Item(2)
  • Re: Comparing Integer values in paragraphs and bold higher value


    Not sure if this is a potential issue or not...


    You use

    Code
    ....Range.Words(11).Select

    to select a value to make bold. Problem is Word treats the decimal as the 'end of a word' but the actual value in the document might be 1471.442 - you're only going to bold the integer portion of that number.

  • Re: Comparing Integer values in paragraphs and bold higher value


    First off, thank you for taking the time to look at the issue and the suggestions you have posted thus far.


    Let me further explain: I'm using the "junct str" as a trigger to analyze the 2 numbers in the "water surface elevation" column. This output describes the water surface elevation for storm drains and the water surface elevation value is needed at "junct str" when there is a lateral introduced to the system, to further analyze that lateral in the next analysis ( another output data that is). The output doesn't tell you if there's a lateral, but you can tell easily by looking at the "Q (cfs)" column, since the Q value will change. So really, i need to do something like ...if this paragraph has "junct str", then if these 2 other paragraphs area equal( the Q values), then do nothing, otherwise if the elevation in the paragraph x > elevation i paragraph y, then bold the greater value, otherwise bold the other value. Do you think theres another way to do all this besides using "if else" statements? I will look into the suggestions that you have posed so far. Just thought I'd reply as soon as possible. :)


    I hope this makes sense.

  • Re: Comparing Integer values in paragraphs and bold higher value


    First off, thank you for taking the time to look at the issue and the suggestions you have posted thus far.


    Let me further explain: I'm using the "junct str" as a trigger to analyze the 2 numbers in the "water surface elevation" column. This output describes the water surface elevation for storm drains and the water surface elevation value is needed at "junct str" when there is a lateral introduced to the system, to further analyze that lateral in the next analysis ( another output data that is). The output doesn't tell you if there's a lateral, but you can tell easily by looking at the "Q (cfs)" column, since the Q value will change. So really, i need to do something like ...if this paragraph has "junct str", then if these 2 other paragraphs area equal( the Q values), then do nothing, otherwise if the elevation in the paragraph x > elevation i paragraph y, then bold the greater value, otherwise bold the other value. Do you think theres another way to do all this besides using "if else" statements? I will look into the suggestions that you have posed so far. Just thought I'd reply as soon as possible. :smile:


    I hope this makes sense.

  • Re: Comparing Integer values in paragraphs and bold higher value


    Quote from cytop;747407

    Not sure if this is a potential issue or not...


    You use

    Code
    ....Range.Words(11).Select

    to select a value to make bold. Problem is Word treats the decimal as the 'end of a word' but the actual value in the document might be 1471.442 - you're only going to bold the integer portion of that number.



    Hi!


    Interesting. I wasn't aware of that fact. I'll keep that in mind and look further into it. Thanks for the reply! :)

  • Re: Comparing Integer values in paragraphs and bold higher value


    you will have to explain exactly what you mean
    find junct str
    then compare
    what to what
    the "Q (cfs)" is the next row down?
    I really don't have any idea with out explanation
    Remember I have no understanding of the process and only need the step explained of exactly which values and where they are

  • Re: Comparing Integer values in paragraphs and bold higher value


    Think I got it


    find junct str
    compare "Q (cfs)" above the "junction str" to the "Q (cfs)" below "junction str"
    if equal do nothing
    if not then
    compare "water level" above to the" water level" below and highlight the highest value


    is that it?

  • Re: Comparing Integer values in paragraphs and bold higher value


    maybe ...

  • Re: Comparing Integer values in paragraphs and bold higher value


    Hi mbecerra24
    Try this
    only way to deal with the large number ( in the Thousands) was with regular expression

  • Re: Comparing Integer values in paragraphs and bold higher value


    Hi Pike


    Just wanted to let you know that it worked great and thank you for your help. I've never heard of using "regular expressions " but now that i know what to look for, i will study and look into that since i will be dealing
    with word processing in the future. Thanks again, i appreciate your help. Have a good day.

  • Re: Comparing Integer values in paragraphs and bold higher value


    Hi mbecerra24


    No thank you for posting an interesting puzzle


    have remove all your quotes .. in future just remember that they are not needed and just clutter the threads


    improvement on this snippet of syntax

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!