Loop through each worksheet

noora19

New Member
Joined
Aug 3, 2010
Messages
41
I am trying to loop the code below through all worksheets within a workbook, but so far have been unsuccesful. The code between the 'for each' and 'next' statement is only a small part of my actual code, but I am not understanding why it is only running the code for the active worksheet, not all worksheets. What am I missing?

Sub AllSheets()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets

Range("C3:I3").Select
Application.CutCopyMode = False
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With

GoToNextSheet:
Next ws

End Sub
 
Maybe this also:

Code:
Sub MaybeThis()
Dim WS As Worksheet
For Each WS In Worksheets
    With WS.Range("C3:I3")
        .MergeCells = True
        .Borders.Weight = xlMedium
        .Font.Color = -6684673
        .Interior.Pattern = xlSolid
        .Interior.Color = 10092543
    End With
Next WS
End Sub

Question though? Are you intentionally making both the font and the cell background yellow?

AMAS
 
Upvote 0

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

Forum statistics

Threads
1,224,607
Messages
6,179,871
Members
452,949
Latest member
Dupuhini

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