How to apply number format to multiple column using loop or best way?

dmadhup

Board Regular
Joined
Feb 21, 2018
Messages
146
Office Version
  1. 365
I am applying number format to multiple columns using the following code. however, I would like to optimize it so that it runs faster.
Range("AC18").Resize(Cells(Rows.Count, "B").End(xlUp).Row - 17).NumberFormat = "$#,##0.000_);[Red]($#,##0.000)"
Range("AD18").Resize(Cells(Rows.Count, "B").End(xlUp).Row - 17).NumberFormat = "$#,##0.000_);[Red]($#,##0.000)"
Range("AF18").Resize(Cells(Rows.Count, "B").End(xlUp).Row - 17).NumberFormat = "$#,##0.000_);[Red]($#,##0.000)"
Range("AG18").Resize(Cells(Rows.Count, "B").End(xlUp).Row - 17).NumberFormat = "$#,##0.000_);[Red]($#,##0.000)"
Range("AI18").Resize(Cells(Rows.Count, "B").End(xlUp).Row - 17).NumberFormat = "$#,##0.000_);[Red]($#,##0.000)"
Range("AJ18").Resize(Cells(Rows.Count, "B").End(xlUp).Row - 17).NumberFormat = "$#,##0.000_);[Red]($#,##0.000)"
Range("AL18").Resize(Cells(Rows.Count, "B").End(xlUp).Row - 17).NumberFormat = "$#,##0.000_);[Red]($#,##0.000)"
Range("AM18").Resize(Cells(Rows.Count, "B").End(xlUp).Row - 17).NumberFormat = "$#,##0.000_);[Red]($#,##0.000)"


Range("AO18").Resize(Cells(Rows.Count, "B").End(xlUp).Row - 17).NumberFormat = "$#,##0.000_);[Red]($#,##0.000)"
Range("AP18").Resize(Cells(Rows.Count, "B").End(xlUp).Row - 17).NumberFormat = "$#,##0.000_);[Red]($#,##0.000)"


Range("AR18").Resize(Cells(Rows.Count, "B").End(xlUp).Row - 17).NumberFormat = "$#,##0.000_);[Red]($#,##0.000)"
Range("AS18").Resize(Cells(Rows.Count, "B").End(xlUp).Row - 17).NumberFormat = "$#,##0.000_);[Red]($#,##0.000)"
 
Last edited:

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
This single line of code will do the same thing as all of the lines of code you posted in Message #1 ...
Code:
[table="width: 500"]
[tr]
	[td]Intersect(Rows("18:" & Cells(Rows.Count, "B").End(xlUp).Row), Range("AC:AD,AF:AG,AI:AJ,AL:AM,AO:AP,AR:AS")).NumberFormat = "$#,##0.000_);[Red]($#,##0.000)"[/td]
[/tr]
[/table]
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,194
Members
453,021
Latest member
pingpong7117

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