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

Code:
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
 

Trebor76

Well-known Member
Joined
Jul 23, 2007
Messages
4,467
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
 

sweeneytime

Board Regular
Joined
Aug 23, 2010
Messages
183
Thanks Robert, yeah I had intended running it from the actuals sheets, works perfectly.

Cheers,
Alan
 

Trebor76

Well-known Member
Joined
Jul 23, 2007
Messages
4,467
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
 

Forum statistics

Threads
1,081,560
Messages
5,359,608
Members
400,538
Latest member
leon_oscar

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top