Worksheet macro to set horizontal alignment of certain cells in certain sheets

suarezri

New Member
Joined
Sep 26, 2014
Messages
5
Hi all,

I'm trying to figure out if there is some code that I can put into "ThisWorkbook" that will allow me to select certain sheets and use either "Columns("A:e").HorizontalAlignment = xlCenter" or "Columns("A:e").HorizontalAlignment = xlLeft"

My other option is to go into each individual worksheet and put the code in, which I know will work, just seeing if there is an easier way to hit ~50 sheets at once. Thanks!
 
Hello,

you could loop through the sheets and run the code. If there is an easy way to determine which sheets you want to run on?

Code:
Sub RUB_CODE_ON_SHEETS()
    For MY_SHEETS = 1 To ActiveWorkbook.Sheets.Count
        Select Case Sheets(MY_SHEETS).Name
            Case "Sheet1", "Sheet2"
                'run your code
        End Select
    Next MY_SHEETS
End Sub

put this in a standard module.
 
Upvote 0

Forum statistics

Threads
1,226,864
Messages
6,193,416
Members
453,797
Latest member
Fly2025

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