![]() |
|
#1
|
|||
|
|||
![]()
Or another presentation of Greg's idea:
Code:
Sub ScratchMacro() 'Coded by Gregory K. Maxey 'https://www.msofficeforums.com/184580-post31.html Dim oRng As range Set oRng = ActiveDocument.range With oRng.Find .text = "<[0-9]{4,5}>" .MatchWildcards = True While .Execute If InStr(oRng.text, "2") > 0 Then MsgBox oRng.text Wend End With lbl_Exit: Exit Sub End Sub Greg and Batman1, thank you for another good lesson! |
#2
|
|||
|
|||
![]() Quote:
If the data is: a3452b 13452 then the code with .text = "[0-9]{4,5}" will find both 3452 and 13452. Meanwhile, the result 13452 is not good because 2 appears in the fifth place and not in 1-4 |
#3
|
|||
|
|||
![]()
In the code
Code:
<[0-9]{4,5}> Code:
Sub ScratchMacro() 'Coded by Gregory K. Maxey 'https://www.msofficeforums.com/184580-post31.html Dim oRng As range Set oRng = ActiveDocument.range With oRng.Find .text = "<[0-9]{4,5}>" .MatchWildcards = True While .Execute If InStr(left(oRng.text, 4), "2") > 0 Then MsgBox oRng.text Wend End With lbl_Exit: Exit Sub End Sub |
#4
|
|||
|
|||
![]() Quote:
I have already explained that the task does not require the number to be a word - it can be part of a word. With data: 13452234567 a3452b 67892 123456 23556789 3456789 a234667 13452234567 a3452b 1342 222 podany kod znajdzie tylko 1342 . Tymczasem wyniki = 34522 3452 7892 12345 23556 23466 34522 3452 1342 |
#5
|
|||
|
|||
![]()
That's clear as mud. In 13452234567 should the code find 34522 and in 123456 12345 ? Then what is the rule/principle of the search? If "Find in the sequence all numbers consisting of 4 or 5 digits, whose first 4 digits have at least 1 digit 2", then 13452234567 contains 3452, 2345, 23456, correct? Ok, never mind! I'm getting too obsessed with the topic and stressing you with my questions.
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
alex100 | Word VBA | 1 | 01-02-2021 02:39 PM |
![]() |
totoMSOF | Word VBA | 19 | 03-11-2019 01:28 PM |
![]() |
abdan | Word VBA | 3 | 01-18-2019 09:38 PM |
Macro help regex | subspace3 | Word VBA | 1 | 10-15-2014 09:53 AM |
Regex in Word: Replaced strings are in disorder | chgeiselmann | Word | 0 | 04-26-2009 11:33 AM |