How do I get macro to change font on all sheets when opening

ghrek

Active Member
Joined
Jul 29, 2005
Messages
426
Hi

I have this macro that changes the font on the 1st page of a workbook but im trying to do it on all sheets in the workbook. How do I do it?

VBA Code:
Private Sub Workbook_Open()
With Sheets(1)
        .Cells.Font.Name = "Arial Narrow"
        .Cells.Font.Size = 11
        .Cells.VerticalAlignment = xlCenter
    End With
End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Hello ghrek, try this:
VBA Code:
Private Sub Workbook_Open()
Dim i As Integer

For i = 1 To Sheets.Count

    With Sheets(i)
        .Cells.Font.Name = "Arial Narrow"
        .Cells.Font.Size = 11
        .Cells.VerticalAlignment = xlCenter
    End With
Next i
End Sub

It will loop through each sheet and update the cells formatting.
 
Upvote 0
Use this:
VBA Code:
Option Explicit
Private Sub Workbook_Open()
    Dim sht    As Worksheet
    Application.ScreenUpdating = False
    For Each sht In Worksheets
        With sht
            .Cells.Font.Name = "Arial Narrow"
            .Cells.Font.Size = 11
            .Cells.VerticalAlignment = xlCenter
        End With
    Next sht
    Application.ScreenUpdating = True
End Sub

PS. Hi to all. Sorry, didn't update the page :sleep:.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,694
Members
448,979
Latest member
DET4492

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