Change columns cell format with VBA

nikolaikolev

New Member
Joined
Nov 22, 2011
Messages
24
Dear,
i use the following macro to change the cell format of a single column (AY), but i want to change the cells format in a few columns that are not next to each other (for example columns A, W, AA, BW)
How can I do that ?

With Sheet1.Range("AY8", "AY10000")
.NumberFormat = "$#,##0.00"
.Value = .Value
End With
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Do you have formulae in those columns that need converting to values, or do you just want to change the number format?
 
Upvote 0
Something like this. I added the numbers so we could check the formatting...

VBA Code:
Sub MultiRange()

    With Sheet1.Range("A1:A10, D1:D5,G5:G7")
        .Value = 10
        .NumberFormat = ("$#,##0.00")
    End With

End Sub
 
Upvote 0
In that case you will need to convert those numbers into proper numbers, for the format to work. Are you happy with that?
 
Upvote 0

Forum statistics

Threads
1,216,905
Messages
6,133,392
Members
449,806
Latest member
nmusoke17

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