Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 03-13-2022, 10:57 PM
Bikram Bikram is offline Inserting comma on numerical figures Windows 10 Inserting comma on numerical figures Office 2007
Advanced Beginner
Inserting comma on numerical figures
 
Join Date: Jul 2021
Location: Nepal
Posts: 97
Bikram is on a distinguished road
Default

I have applied the following way of dealing with the above problem. How can it be better??
Code:
Sub Comma()

    Selection.find.ClearFormatting
    With Selection.find
        .Text = "[0-9]{3,}"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = True
    End With
    With Selection
    Do While .find.Execute = True
    If IsNumeric(.Range.Text) = True Then
    Select Case .Range.Characters.Count
    Case 4
    If .Range.Text Like "20??" Then
    
    Else
    .Range.Characters(1).InsertAfter (",")
    .MoveRight wdCharacter, 1
    End If
    Case 5
    .Range.Characters(2).InsertAfter (",")
    .MoveRight wdCharacter, 1
    Case 6
    .Range.Characters(1).InsertAfter (",")
    .Range.Characters(4).InsertAfter (",")
    .MoveRight wdCharacter, 1
    Case 7
    .Range.Characters(2).InsertAfter (",")
    .Range.Characters(5).InsertAfter (",")
    .MoveRight wdCharacter, 1
    Case 8
    .Range.Characters(1).InsertAfter (",")
    .Range.Characters(4).InsertAfter (",")
    .Range.Characters(7).InsertAfter (",")
    .MoveRight wdCharacter, 1
   Case 9
    .Range.Characters(2).InsertAfter (",")
    .Range.Characters(5).InsertAfter (",")
    .Range.Characters(8).InsertAfter (",")
    .MoveRight wdCharacter, 1
   Case 10
    .Range.Characters(1).InsertAfter (",")
    .Range.Characters(4).InsertAfter (",")
    .Range.Characters(7).InsertAfter (",")
    .Range.Characters(10).InsertAfter (",")
    .MoveRight wdCharacter, 1
    
    End Select
    End If
    Loop
        End With

    
End Sub
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 05:05 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