Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 03-14-2022, 02:16 PM
Guessed's Avatar
Guessed Guessed is offline Inserting comma on numerical figures Windows 10 Inserting comma on numerical figures Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

It can be shorter
Code:
Sub Comma()
  Dim aRng As Range
  Set aRng = ActiveDocument.Range
  With aRng.Find
    .ClearFormatting
    .Text = "[0-9]{4,}"
    .Wrap = wdFindStop
    .MatchWildcards = True
    Do While .Execute = True
      If aRng.Text Like "20??" Then
        aRng.HighlightColorIndex = wdBrightGreen
      Else
        aRng.Text = Format(aRng.Text, "#,##0")
      End If
      aRng.Collapse Direction:=wdCollapseEnd
    Loop
  End With
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
 

Tags
comma, vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting comma on numerical figures Code to find numerical string + space throughout document & replace them with Comma Robert Kay Word VBA 6 02-21-2018 04:41 PM
List of figures with several labels (caption) - Table of Figures sorting ibra_ca Word 2 10-11-2017 07:02 AM
Automatic table of figures includes one of the figures, not just the caption - help! sarahlt Word 1 09-28-2014 09:34 AM
Inserting comma on numerical figures Inserting Table of Figures Insists on Overwriting Existing sleake Word 8 09-15-2013 02:42 PM
Plotting Numerical and Non-numerical Data Set Ife Excel 0 04-23-2012 10:35 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:40 PM.


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