Format columns using numbers instead of letters

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,834
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I want to format some columns on a worksheet using numbers instead of letters.

Both versions of the following code are in a standard module.

This uses letters:

Code:
    Sheet1.Range("A:A,C:C").NumberFormat = "General"
    Sheet1.Range("B:B,D:D").NumberFormat = "0"
    Sheet1.Range("E:E").NumberFormat = "#,##0"

and this uses numbers:

Code:
    Sheet1.Range(Columns(1), Columns(3)).NumberFormat = "General"
    Sheet1.Range(Columns(2), Columns(4)).NumberFormat = "0"
    Sheet1.Range(Columns(5), Columns(5)).NumberFormat = "#,##0"

They both work IF Sheet1 is already selected.

However, if Sheet1 is NOT selected, only the one using letters work.

Is there a way to make the numbers version work without the need to select the sheet first?

Thanks
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Forum statistics

Threads
1,215,364
Messages
6,124,507
Members
449,166
Latest member
hokjock

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