Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-06-2025, 03:21 PM
batman1 batman1 is offline Find Challenge Windows 11 Find Challenge Office 2013
Advanced Beginner
 
Join Date: Jan 2025
Posts: 57
batman1 is on a distinguished road
Default



Quote:
Originally Posted by gmaxey View Post
This post is a continuation of a discuss that started here:
https://www.msofficeforums.com/word-...x-pattern.html

Code:
Sub ScratchMacroC()
Dim oRng As Range
Set oRng = ActiveDocument.Range
Dim lngIndex As Long
  With oRng.Find
    .Text = "[0-9]{1,}"
    .MatchWildcards = True
    While .Execute
      lngIndex = 1
      If InStr(Left(oRng.Text, 4), "2") > 0 Then
        Select Case Len(oRng.Text)
          Case Is > 4
            Debug.Print Left(oRng.Text, 5)
            lngIndex = 5
          Case Is = 4
            Debug.Print oRng.Text
            lngIndex = 4
        End Select
      End If
      oRng.End = oRng.Start + lngIndex
    Wend
  End With
lbl_Exit:
  Exit Sub
End Sub
I tested it with some data and the code works fine.

In my post #26 I quoted vivek (he later deleted it): "Sometimes regex is more functional than Word standard instruments". And in my opinion there is a code with Regex simpler than Sub ScratchMacroC
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Any work-around for this challenge RRB Word 6 08-22-2023 11:47 AM
Formula challenge 3 criteria JMC44 Excel Programming 0 04-04-2015 07:38 PM
Find Challenge Challenge for a genius ? e.roberts Office 3 07-13-2012 01:36 AM
Find Challenge Sorting Challenge gbaker Excel Programming 11 06-22-2012 09:39 AM
Find Challenge Word Challenge jpotter2 Word 3 03-22-2011 02:07 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:02 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft