Nested For Each loop won't work; can anyone help?

vincecodegreeen

New Member
Joined
Jan 17, 2014
Messages
39
I am trying to paste the same data onto each sheet in the workbook in the same places. I have recorded the actions for the first sheet and tried to loop through the others using a For Each loop. Can anyone tell me what is wrong with the code?
Sub worksheettest()
Dim wbk As Workbook
Dim wks As Worksheet
Set wbk = ThisWorkbook
For Each wks In wbk.Worksheets
Macro1
Next wks


End Sub
Sub Macro1()
'
' Macro1 Macro
'
x = wks.ThisWorkbook + 1




Worksheets("Sheet 1").Activate
Range("C1").Select
Selection.Copy
Sheets("sheet x").Select
Range("P1").Select
ActiveSheet.Paste
Range("H2").Select
ActiveSheet.Paste
Range("X2").Select
ActiveSheet.Paste
Range("D3").Select
ActiveSheet.Paste
Range("L3").Select
ActiveSheet.Paste
Range("T3").Select
ActiveSheet.Paste
Range("AB3").Select
ActiveSheet.Paste
Range("B4").Select
ActiveSheet.Paste
Range("F4").Select
ActiveSheet.Paste
Range("J4").Select
ActiveSheet.Paste
Range("N4").Select
ActiveSheet.Paste
Range("R4").Select
ActiveSheet.Paste
Range("V4").Select
ActiveSheet.Paste
Range("Z4").Select
ActiveSheet.Paste
Range("AD4").Select
ActiveSheet.Paste
End Sub


Thanks
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
What about
Code:
Sub Macro1()
Dim ws As Worksheet
Sheets("Sheet1").Range("C1").Copy
For Each ws In Worksheets
   If ws.Name <> "Sheet1" Then
        ws.Activate
        Range("H2,X2,D3,L3,T3,AB3,B4,F4,J4,N4,R4,V4,Z4,AD4").Select
        ws.Paste
    End If
Next ws
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,136
Messages
6,129,080
Members
449,485
Latest member
greggy

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