Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-16-2021, 01:26 AM
RobertDany RobertDany is offline How to change formatting of only numbers between parenthesis using VBA code? Windows 7 64bit How to change formatting of only numbers between parenthesis using VBA code? Office 2013
Novice
How to change formatting of only numbers between parenthesis using VBA code?
 
Join Date: Jul 2021
Posts: 22
RobertDany is on a distinguished road
Default How to change formatting of only numbers between parenthesis using VBA code?

Hello everyone



I want to change the formating of only numbers between parenthesis using VBA code
like this

img_55.png

Additionally, some parenthesis contain numbers like these (5,12), (53-57), (123,136,156), (123-136,156)

keep in your mind, changing the formating of only numbers, not text nor parenthesis itself.

Thanks in advance
Reply With Quote
  #2  
Old 07-16-2021, 04:57 PM
Guessed's Avatar
Guessed Guessed is offline How to change formatting of only numbers between parenthesis using VBA code? Windows 10 How to change formatting of only numbers between parenthesis using VBA code? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,975
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

I would do this via two consecutive find/replaces. You can record these steps and tidy up the code to make it a macro.

Find: \([0-9\-,]{1,}\)
Replace with: leave box empty but set font format to red
Wildcards On

Find: [\(\)]
Replace with: leave box empty but set font format to auto or black
Wildcards On
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 07-17-2021, 12:37 AM
RobertDany RobertDany is offline How to change formatting of only numbers between parenthesis using VBA code? Windows 7 64bit How to change formatting of only numbers between parenthesis using VBA code? Office 2013
Novice
How to change formatting of only numbers between parenthesis using VBA code?
 
Join Date: Jul 2021
Posts: 22
RobertDany is on a distinguished road
Default

Wow Mr. Guessed
I thank you so much

Excuse me Mr. Guessed,
What if I want to change the formatting of everything inside the parenthesis
what I shall write in the Find
Also in the same idea (comma and dash among elements inside the parenthesis).

Lastly, how to make your answer a correct answer or solved question.

Thanks
Reply With Quote
  #4  
Old 07-21-2021, 04:13 PM
Peterson Peterson is offline How to change formatting of only numbers between parenthesis using VBA code? Windows 10 How to change formatting of only numbers between parenthesis using VBA code? Office 2019
Competent Performer
 
Join Date: Jan 2017
Posts: 141
Peterson is on a distinguished road
Default

To keep the parentheses, commas, and dashes black, do the following four find/replaces:

Find: ([\(])([0-9\-,]{1,})([\)])
Replace with: \1qq\2\3qq
Leave box empty but set font format to red
Wildcards On


Find: ([\(])(qq)
Replace with: \1
Leave box empty but set font format to auto or black
Wildcards On


Find: ([\)])(qq)
Replace with: \1
Leave box empty but set font format to auto or black
Wildcards On


Find: [,\-]
Set the font color to red
Replace with: Leave blank
Set the font color to black or auto
Wildcards On



NOTES:
  • The "qq" is dummy text, to make sure that the only parentheses found/replaced are the ones surrounding your numbers. I am assuming that there's a possibility that you have other, red text that you do NOT want altered.
  • You have to do this in four steps because, while you can search for multiple items in a string (by grouping them in parentheses), you cannot selectively apply formatting to only a portion of the string, i.e., you can't apply red to the numbers while leaving the parentheses black.
  • If you do NOT have other colored text, then you can do all of the above more simply, as follows:


Find: [\(][0-9\-,]{1,}[\)]
Replace: Leave blank
Set font color to red
Wildcards On



Find: [\(\)\-,]
Set font color to red

Replace with: Leave blank
Set font color to black or auto
Wildcards On
Reply With Quote
Reply

Tags
microsoft word, vba change color, vba editor



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to change formatting of only numbers between parenthesis using VBA code? VBA Code to search for field codes with certain text before the Field code and to change style welcometocandyland Word VBA 4 02-08-2017 06:53 PM
How to change formatting of only numbers between parenthesis using VBA code? code to rewrite numbers romanticbiro Word VBA 7 02-15-2014 03:04 PM
How to change the formatting of numbers without changing the numbers? sullengirl Word 2 01-27-2014 03:06 PM
How do I refer to page numbers, when the numbers change as I prepare the document? StevenD Word 5 11-29-2012 12:52 AM
Extract Numbers from Zip Code Karen615 Excel 3 09-21-2011 06:54 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:19 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft