Format columns using numbers instead of letters

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,832
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

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,214,632
Messages
6,120,652
Members
448,975
Latest member
sweeberry

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