#1
|
|||
|
|||
Find & Replace to insert thousands separators
I can't quite get the syntax right for replacing a number with the thousand separator. Before 1266.89 3479.52 After 1,266.89 3,479.52 I tried F/R with wildcard Find: ([!/-//][0-9])([0-9]{4})(.[0-9]{2}))> Replace: \1,\2 |
#2
|
|||
|
|||
maybe just
Code:
Option Explicit Sub FormatNumbers() Dim lngdb As Long If Selection.Type = wdSelectionIP Then ActiveDocument.Range(0, 0).Select lngdb = wdFindContinue Else lngdb = wdFindStop End If With Selection.Find .ClearFormatting .Text = "[0-9]{4,}" .Replacement.Text = "" .Forward = True .Wrap = lngdb .Format = False .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = True Do While .Execute Selection.Text = Format$(Selection.Text, "#,##0") If lngdb = wdFindContinue Then Selection.Collapse wdCollapseEnd Else Exit Sub End If Loop End With End Sub Last edited by pike; 10-18-2019 at 08:11 PM. |
#3
|
|||
|
|||
Thank you Pike. This will do it.
|
#4
|
|||
|
|||
no problem. Sometimes RegExp match and replace is easier than the word F/R
|
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Find and Replace/Insert 'CR', delete leading Spaces wherever a user Clicks in a Word document | DavidL | Word VBA | 7 | 04-04-2018 12:01 AM |
Find and Replace - How to insert brackets around all numbers in a doc | Natedogg | Word | 2 | 05-21-2015 07:16 AM |
Insert text at the end of a sentence Find/Replace | AlmostFriday | Word | 6 | 06-17-2012 05:21 AM |
Bad view when using Find and Find & Replace - Word places found string on top line | paulkaye | Word | 4 | 12-06-2011 11:05 PM |
Find & Replace Insert Issue | mipacker | Word | 0 | 02-18-2009 08:59 AM |