pliskers
Active Member
- Joined
- Sep 26, 2002
- Messages
- 461
- Office Version
- 2016
- Platform
- Windows
I'm trying to write code that will loop through all the sheets in a workbook and, on each sheet, copy the contents of cells A1:B1 on that sheet to from row 4 through the last row on that sheet (as defined by column C). The macro does not move through the sheets. Rather, it's performing the copy paste from each sheet but staying on the first tab. I must be missing a step. Can someone please have a look and let me know?
Thank you!
Sub Loop_()
Dim wb As ThisWorkbook
Dim ws As Worksheet
Dim TableName As String
Dim LstObj As ListObjects
For Each ws In ThisWorkbook.Worksheets
With ws
lastrow = Range("C1000000").End(xlUp).Row
ws.Range("A1:B1").Copy
Range("A4:B" & lastrow).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
lastrow = vbNullString
End With
Next ws
End Sub
Thank you!
Sub Loop_()
Dim wb As ThisWorkbook
Dim ws As Worksheet
Dim TableName As String
Dim LstObj As ListObjects
For Each ws In ThisWorkbook.Worksheets
With ws
lastrow = Range("C1000000").End(xlUp).Row
ws.Range("A1:B1").Copy
Range("A4:B" & lastrow).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
lastrow = vbNullString
End With
Next ws
End Sub