Copy sheets to the last sheet on another workbook

sweeneytime

Board Regular
Joined
Aug 23, 2010
Messages
183
Hi guys,

I want the macro to loop through the workbook and copy sheets that have "Income" in A5, the selection part works.

Each sheet that has "Income" should be copied to the last sheet in the "CCActuals" workbook.

I am getting error an 1004. Anybody have an ideas?

Have tried many places to find an answer and the macro recorded doesn't help on these undefined sheet matters.

Thank,
Alam

PHP:
Sub SelectCC()
    Dim WS As Worksheet
    
    
    'Activate Actuals WB
    Windows("2009-10 Reforecast with actuals to June10  v2 Alan.xlsm").Activate
   
   
    'Select sheets with "INCOME" in A5
    For Each WS In ActiveWorkbook.Worksheets
            If WS.Range("A5").Text = ("INCOME") Then
            
                WS.Copy after:=Workbooks("CC Actuals.xlsm").Sheets.Count
            
            End If
    Next WS
End Sub
 

Excel Facts

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

Assuming 'CC Actuals.xlsm' is open, the following should do the trick:

Code:
Sub Macro2()

    For Each WS In ActiveWorkbook.Worksheets
        If WS.Range("A5").Text = ("INCOME") Then
            WS.Copy After:=Workbooks("CC Actuals.xlsm").Sheets(Workbooks("CC Actuals.xls").Worksheets.Count)
        End If
    Next WS

End Sub

HTH

Robert
 
Upvote 0
As long as the 'CC Actuals.xlsm' workbook is open that's fine - i.e. you can run the code from any workbook in the same session.

I'm glad to hear it all seems to be all sorted in any case.

Cheers,

Robert
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,517
Members
449,088
Latest member
RandomExceller01

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