Macro should run whenever a new sheet is added

Penny Bangalore

Board Regular
Joined
Apr 17, 2015
Messages
79
hello,

Need help please

i have a macro which will change the number format to currency format ( $ ) .. i want this to be happened whenever a new worksheets is added to workbook..

can anyone help me please


Sub Formatcurrency()
Dim iSht As Integer
Dim rng As Range


For iSht = 1 To Sheets.Count
Set rng = Worksheets(iSht).UsedRange
With rng
.NumberFormat = "$#,##0.00"
End With
Next
End Sub
 
Last edited:

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Why not just change style Normal to use that number format?
 
Upvote 0
Hi,

In vb editor double click 'ThisWorkBook' and paste this in on the right.


Private Sub Workbook_NewSheet(ByVal Sh As Object)
Dim iSht As Long
Dim rng As Range
For iSht = 1 To Sheets.Count
Set rng = Worksheets(iSht).UsedRange
With rng
.NumberFormat = "$#,##0.00"
End With
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,871
Members
449,055
Latest member
excelhelp12345

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