Share via

Word if the value is higher than $30,000 then highlight Turquoise.

SteveD 145 Reputation points
2026-03-06T20:22:45.9466667+00:00

Hello from Steve

In a word document is it possible please, if the value is higher than $30,000 then highlight Turquoise VBA

Microsoft 365 and Office | Word | For home | Windows
0 comments No comments

2 answers

Sort by: Most helpful
  1. John Korchok 231.2K Reputation points Volunteer Moderator
    2026-03-06T20:53:25.2466667+00:00

    This should get you started:

    Sub HighlightValuesOver30000()
        Dim rng As Range
        Dim findRange As Range
        Dim numValue As Double
        
        ' Start from the beginning of the document
        Set rng = ActiveDocument.Content
        rng.Find.ClearFormatting
        rng.Find.Replacement.ClearFormatting
        
        ' Search for numbers (including commas and decimals)
        With rng.Find
            .Text = "<[0-9,\.]{1,}>"
            .MatchWildcards = True
            .Forward = True
            .Wrap = wdFindStop
        End With
        
        ' Loop through all matches
        Do While rng.Find.Execute
            Set findRange = rng.Duplicate
            
            ' Remove commas for numeric conversion
            On Error Resume Next
            numValue = CDbl(Replace(findRange.Text, ",", ""))
            On Error GoTo 0
            
            ' Check if number is greater than 30000
            If numValue > 30000 Then
                findRange.HighlightColorIndex = wdTurquoise
            End If
            
            ' Move to next match
            rng.Collapse wdCollapseEnd
        Loop
        
        MsgBox "Highlighting complete.", vbInformation
    End Sub
    
    2 people found this answer helpful.

  2. Q&A Assist
    2026-03-06T20:22:55.9866667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    Word does not support conditional formatting of text based on numeric values in the way that Excel does, so it cannot automatically highlight values greater than $30,000 in turquoise purely by rule.

    However, text can be manually highlighted in turquoise (or programmatically via an add-in or script):

    1. Select the value(s) to highlight.
    2. On Windows desktop Word, go to Home and select the arrow next to Text Highlight Color.
    3. Choose Turquoise from the available highlight colors.

    If using a Word JavaScript add-in, the highlight color can be set in code, for example:

    await Word.run(async (context) => {
      const selection = context.document.getSelection();
      // After programmatically determining the value > 30000,
      // apply turquoise highlight to the selection
      selection.font.highlightColor = 'Turquoise';
      await context.sync();
    });
    

    Note that only the built‑in highlight colors (including "Turquoise") are available in Office for Windows Desktop; other colors are mapped to the closest available color.


    References:

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.