Share via

Word find exact numeral using vba

SteveD 145 Reputation points
2026-04-08T03:35:59.7066667+00:00

Hello from Steve

3 ST VINCENT

13 STILL BANGON

3 ST VINCENT

Above the numeral 3 need find the same second occurence

At this time running a vba it finds 13 which I do not want

Is it possible please to find the second numeral 3 using vba.

Developer technologies | Visual Basic for Applications
0 comments No comments

2 answers

Sort by: Most helpful
  1. Killian N 240 Reputation points Independent Advisor
    2026-04-08T10:05:35.3333333+00:00

    Hi @SteveD, 

    This happens because Word’s Find method matches substrings by default, so searching for 3 also matches 13. 

    1. To ensure Word finds only the exact numeral 3 (and not 13), you need to either: 
    2. Match the whole word using wildcards, and 

    Move the search range forward after the first match so the second occurrence is found. 

    Below is a working VBA example that does exactly that. 

    VBA Example (Find second exact “3” only) 

    Sub FindSecondThree()
        Dim rng As Range
        Set rng = ActiveDocument.Range
        With rng.Find
            .ClearFormatting
            .Text = "<[3]>"          ' match only the standalone number 3
            .MatchWildcards = True
            .MatchWholeWord = False  ' wildcard already ensures whole word
            .MatchCase = False
            .Forward = True
            .Wrap = wdFindStop
        End With
        ' Find first occurrence
        If rng.Find.Execute Then
            
            ' Find second occurrence
            If rng.Find.Execute Then
                rng.Select   ' this is the second standalone 3
            End If
            
        End If
    End Sub
    

    Furthermore, you can follow the steps below to find the standalone numeral 3.

    1. Loop through all matches (more flexible VBA) 

    Instead of calling .Execute twice, you can loop and stop at the 2nd match. This is cleaner if later you want the 3rd, 4th, etc. 

    Sub FindNthThree() 
      
        Dim rng As Range 
        Dim count As Integer 
         
        Set rng = ActiveDocument.Range 
        count = 0 
      
        With rng.Find 
            .ClearFormatting 
            .Text = "<[3]>" 
            .MatchWildcards = True 
            .Forward = True 
            .Wrap = wdFindStop 
        End With 
      
        Do While rng.Find.Execute 
            count = count + 1 
             
            If count = 2 Then 
                rng.Select 
                Exit Do 
            End If 
             
            rng.Collapse wdCollapseEnd 
        Loop 
      
    End Sub 
    
    

    2. Use Word's “Find All” + index (manual or VBA hybrid) 

    You can collect all matches first, then pick the second. It's useful when you want to store or process multiple matches 

    Sub FindSecondViaCollection() 
      
        Dim rng As Range 
        Dim results As New Collection 
      
        Set rng = ActiveDocument.Range 
      
        With rng.Find 
            .Text = "<[3]>" 
            .MatchWildcards = True 
            .Forward = True 
            .Wrap = wdFindStop 
        End With 
      
        Do While rng.Find.Execute 
            results.Add rng.Duplicate 
            rng.Collapse wdCollapseEnd 
        Loop 
      
        If results.Count >= 2 Then 
            results(2).Select 
        End If 
      
    End Sub 
    
    

    3. Add-in / Tool options 

    If you prefer no coding or reusable tools, here are options: 

    Built-in Advanced Find (no add-in) 

    • Press Ctrl + H  
    • Enable Use wildcards  
    • Search: <[3]>  
    • Click Find In => Main Document  

    This highlights all matches, then just jump to the second one.  Note: Please understand that my initial response does not always resolve the issue immediately. However, with your help and more detailed information, we can work together to find a solution.  

    I hope this information is useful. Additionally, as other users have raised similar concerns and may not be aware of where to share their feedback, I hope this response helps clarify the situation and suggests a potential next step. Highlighting this information can make it more visible to others in the community who may be facing the same issue, making it easier for them to find guidance and contribute their feedback as well. 

    Thank you again for your time and for raising this important usability concern. If you have any further questions or need additional assistance, please don’t hesitate to reach out. 

    I look forward to your thoughts on this. 


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".      

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.  

    1 person found this answer helpful.

  2. Q&A Assist
    2026-04-08T03:36:08.9666667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    Use the Word Find object with MatchWildcards and then skip the first match.

    To find the second occurrence of the standalone numeral 3 (and avoid the 3 in 13), use a wildcard search that enforces a word boundary, then call Execute twice:

    Sub FindSecondThree()
        Dim rng As Range
        Set rng = ActiveDocument.Range
    
        With rng.Find
            .ClearFormatting
            .Text = "<[3]>"          'find 3 as a whole word
            .MatchWildcards = True
            .MatchWholeWord = False  'handled by wildcards
            .MatchCase = False
            .Forward = True
            .Wrap = wdFindStop
        End With
    
        'First occurrence
        If rng.Find.Execute Then
            'Second occurrence
            If rng.Find.Execute Then
                rng.Select          'this is the second 3
            End If
        End If
    End Sub
    

    Explanation of the pattern:

    • < and > are word-boundary markers in Word wildcard searches.
    • [3] matches the digit 3 only.

    This ensures that 13 is not matched, and the second Execute selects the second occurrence of 3.


    References:

    1 person found this answer helpful.

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.