currency format columns in listobject table

ajm

Well-known Member
Joined
Feb 5, 2003
Messages
2,007
Office Version
  1. 365
Platform
  1. Windows
hi all, with the following snippet, i am attempting to reformat several columns to currency in the table i have created.

Code:
With Sheets("ITR")
            .ListObjects.Add(SourceType:=xlSrcRange, Source:=.Cells(1).CurrentRegion, _
                XlListObjectHasHeaders:=xlYes, TableStyleName:="TableStyleMedium2").Name = "TblITR"
            .Columns("U:Z", "AG", "AN:AU", "AZ:BA").Style = "Currency"
            .Columns("U:Z", "AG", "AN:AU", "AZ:BA").NumberFormat = "_-$* #,##0_-;-$* #,##0_-;_-$* ""-""??_-;_-@_-"
            .Cells.EntireColumn.AutoFit
        End With

it falls over on this line - .Columns("U:Z", "AG", "AN:AU", "AZ:BA").Style = "Currency"-

where i try to change all the currency columns at the one time. Do i need to have a new line for each column band?
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
I don't believe the columns property works the way you want.

Either of these will work, if that helps:-
VBA Code:
    Range("C:C,E:F").Style = "Currency"
    Range("c1,e1:f1").EntireColumn.Style = "Currency"
 
Upvote 0
thanks alex. i got it to work after i removed the "" around each column(s) AND changed to .Range. The apostrophes still need to go around all the required columns, just not each set of them. Easier to see what i am trying to say.

Instead of: .Columns("U:Z", "AG", "AN:AU", "AZ:BA").Style = "Currency"

I used: .Range("U:Z, AG:AG, AN:AU, AZ:BA").Style = "Currency"
 
Upvote 0
That was the first option I gave. I only gave the 2nd option in case you really hated having to do something like the AG:AG for single columns.
Glad you were able to get it to work. Thanks for letting me know.
 
Upvote 0

Forum statistics

Threads
1,215,191
Messages
6,123,553
Members
449,108
Latest member
rache47

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