Help with For each Sheet next

cprince

Board Regular
Joined
Jul 4, 2006
Messages
67
Hi All,

I ve got a workbook with 3 sheets.

Sheet 1 is called "Total"
Sheet 2 is called "mary"
Sheet 3 is called "Jane"

I may have more sheets in the future, so I want it to loop until there are no more sheets.

I need to copy the range A1:A200 in Sheet2 and paste in Sheet1 then,

copy the range A1:A200 in Sheet3 and paste in Sheet1 at the bottom of pasted data.

For each sheet .

Can someone help me with some code for this?
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
Hi
something like
Code:
Sub test()
Dim ws As Worksheet, LastR As Range
Sheets("Total").Columns("a").ClearContents
For Each ws In WorkSheets
     If ws.Name <> "Total" Then
          With Sheets("Total")
              Set LastR = .Range("a" & Rows.Count).End(xlUp).Offset(1)
              If IsEmpty(.Range("a1")) Then Set LastR = .Range("a1")
          End With
          ws.Range("a1:a200").Copy LastR
     End If
Next
End Sub
 

venkat1926

Well-known Member
Joined
Aug 21, 2005
Messages
4,824
try something like this
change to suit you

Code:
Sub test()
Dim i As Integer
Dim dest As Range
For i = 2 To ThisWorkbook.Worksheets.Count
Sheets(i).Activate
' for each sheet row 1 is the same header in all the sheets
Set dest = Sheets(1).Cells(Rows.Count, "a").End(xlUp).Offset(1, 0)
Range(Range("a2"), Range("a2").End(xlDown).End(xlToRight)).Copy dest
Next i
End Sub


venkat
 

Forum statistics

Threads
1,136,699
Messages
5,677,273
Members
419,683
Latest member
MrVBAConfused

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
Top