Looping Through Worksheets

jadamvgrant

New Member
Joined
Jul 14, 2016
Messages
2
Can some one help me in getting my code to loop through all worksheets in WorkBook
Range("B1:P1").Select
Application.CutCopyMode = False
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlTop
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.MergeCells = True
End With
Selection.UnMerge
Range("B1").Select
Selection.Copy
Range("A3:A11").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A3", "P11").Select
Selection.Copy
Sheets("Summary").Select
Range("A" & Rows.Count).End(xlUp).Offset(1).Select
ActiveSheet.Paste
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 1
Range("A5").Select
Selection.End(xlDown).Select
Range("A" & Rows.Count).End(xlUp).Offset(1).Select
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Try this.
Code:
Dim ws As Worksheet

    For Each ws In ActiveWorkbook
    
        With ws
            With .Range("B1:P1")
                .HorizontalAlignment = xlGeneral
                .VerticalAlignment = xlTop
                .WrapText = True
                .Orientation = 0
                .AddIndent = False
                .IndentLevel = 0
                .ShrinkToFit = False
                .MergeCells = True
                .UnMerge
            End With
            
            .Range("B1").Copy
            .Range("A3:A11").PasteSpecial Paste:=xlPasteValues
            .Range("A3", "P11").Copy Sheets("Summary").Range("A" & Rows.Count).End(xlUp).Offset(1)
        End With
        
    Next ws
 
Upvote 0
Sub PayerMix()'
' Payer Mix Macro
Dim ws As Worksheet

For Each ws In ActiveWorkbook

With ws
With .Range("B1:P1")
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlTop
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.MergeCells = True
.UnMerge
End With

.Range("B1").Copy
.Range("A3:A11").PasteSpecial Paste:=xlPasteValues
.Range("A3", "P11").Copy Sheets("Summary").Range("A" & Rows.Count).End(xlUp).Offset(1)
End With

Next ws
End Sub

Gives me an error at "For Each ws In ActiveWorkbook"
 
Upvote 0
jadamvgrant,

Try changing the following line of code:

Code:
For Each ws In ActiveWorkbook


To the following:

Code:
For Each ws In ThisWorkbook.Worksheets
 
Upvote 0

Forum statistics

Threads
1,216,577
Messages
6,131,511
Members
449,653
Latest member
andz

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