loop or combine formatting columns

288enzo

Well-known Member
Joined
Feb 8, 2009
Messages
721
Office Version
  1. 2016
Platform
  1. Windows
I have this bit of code I'm trying to condense.
VBA Code:
    Columns("F:G").NumberFormat = "0"
    Columns("I:J").NumberFormat = "0"
    Columns("L:M").NumberFormat = "0"
    Columns("O:P").NumberFormat = "0"

I've tried the following, but it didn't work.
VBA Code:
    Columns("F:G,I:J,L:M,O:P").NumberFormat = "0"

I also recently learned about looping, but what has me perplexed is how to loop using letters?
My example would be something like
VBA Code:
    Dim r As Long
    
    For r = 9 To 7 Step -1
        Columns(r & ":" & r + 1).NumberFormat = "0"
    Next r
I need help how to use this with column letters.

Thank you
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
How about
VBA Code:
Range("F:G,I:J,L:M,O:P").EntireColumn.NumberFormat = "0"
 
Upvote 0
Solution
How about
VBA Code:
Range("F:G,I:J,L:M,O:P").EntireColumn.NumberFormat = "0"
Thank you, I didn't know you could use "Range" when selecting columns. I assume you can do the same with "EntireRow"?
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,583
Members
449,089
Latest member
Motoracer88

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