gberg

Board Regular
Joined
Jul 16, 2014
Messages
180
Office Version
  1. 365
Platform
  1. Windows
Is there a way to change all cells in a workbook that share a common number format?

I have a workbook with multiple tabs. I would like to be able to have a vba code to change the number formatting for all cells that have this #,##0_ );(#,##0) formatting to #,##0.0,_);(#,##0.0,) and then back again.

There are hundreds if not thousands of cells in my workbook that have the same formatting
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
I had a similar situation a few years ago.
Here's what I did:
• Created a Custom Cell Style that only featured a number format.
• Assigned that cell style to all impacted cells
• Used VBA to toggle the number format for the Custom Cell Style depending on a cell value in a "Control Panel" tab in my workbook

That way, one simple change to the Custom Cell Style can have far reaching impact on the workbook.

Is that something you can work with?
 
Upvote 0
That's intriguing. So you would have one cell that would control the number formatting of all the similar type cells? How would the VBA work?

Thanks,
Greg
 
Upvote 0
I found a solution

Worksheets("Sheet1").Range("F8").NumberFormat = "#,##0.0,_);(#,##0.0,)"
Application.FindFormat.NumberFormat = "#,##0_ );(#,##0)"
Application.ReplaceFormat.NumberFormat = "#,##0.0,_);(#,##0.0,)"
Cells.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder:= _
xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,332
Members
449,077
Latest member
jmsotelo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top