currency format columns in listobject table

ajm

Well-known Member
Joined
Feb 5, 2003
Messages
1,854
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

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Alex Blakenburg

Well-known Member
Joined
Feb 23, 2021
Messages
1,138
Office Version
  1. 365
Platform
  1. Windows
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"
 

ajm

Well-known Member
Joined
Feb 5, 2003
Messages
1,854
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"
 

Alex Blakenburg

Well-known Member
Joined
Feb 23, 2021
Messages
1,138
Office Version
  1. 365
Platform
  1. Windows
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.
 

Forum statistics

Threads
1,136,637
Messages
5,676,916
Members
419,658
Latest member
jahbro

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
Top