Automatically adding commas when numbers reach 4 integers or greater

Hello,

Is there a way to have word automatically add a comma whenever a typed in number reaches past 4 digits?  Right now, I'm manually adding in a comma to write numbers such as $1,000,000.

The short answer is no, but you could use a macro. Type the number e.g. 1000 or 1000.50 and then run the macro immediately afterwards. It will format as 1,000 or 1,000.50 respectively. If you have typed the comma(s) manually it will check the format. For ease of use assign the macro to a keyboard shortcut - http://www.gmayor.com/installing_macro.htm    Note there is no period in the second number string.

Sub FormatNumbers()
Dim orng As Range
    Set orng = Selection.Range
    orng.MoveStartWhile "0123456789.,", wdBackward
    orng.MoveEndWhile "0123456789,"
    If InStr(1, orng.Text, ".") > 0 Then
        orng = Format(orng.Text, "###,###,###,0.00")
    Else
        orng = Format(orng.Text, "###,###,###,0")
    End If
    orng.Collapse wdCollapseEnd
    orng.Select
End Sub

Graham Mayor (Microsoft Word MVP 2002-2019)
For more Word tips and downloads visit my web site
https://www.gmayor.com/Word_pages.htm

4 people found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Hello,

I tried running the marco but it has been erroring out or not adding the commas.

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

I have just copied it from the thread and it works fine - what's the error message?
Graham Mayor (Microsoft Word MVP 2002-2019)
For more Word tips and downloads visit my web site
https://www.gmayor.com/Word_pages.htm

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Hello,

It works now.  I don't know why it wasn't working at first.  Thanks so much!

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated March 16, 2024 Views 5,749 Applies to: