Move sheet to a new workbook based on C3's contents?

poptart141

New Member
Joined
Apr 1, 2013
Messages
4
I have a workbook that has multiple sheets related to current projects my department is working on. Whenever cell C3 in one of these sheets says "Complete" or "Archived," I need that whole sheet to be moved to another workbook, called "CPTS Complete & Archived." Here's the code I have so far, which isn't doing anything:


Code:
Sub MoveSheets()
   Dim NewWorkbook As Workbook
   Set NewWorkbook = Workbooks("CPTS Complete & Archived.xlsx")
    
   If InStr(1, ActiveSheet.Range("C3").Value, "Complete" Or "Archived") > 0 Then
      Application.Workbooks.Open ("C:\Documents and Settings\username\Desktop\CPTS\CPTS Complete & Archived.xlsx")
      ActiveSheet.Move After:=NewWorkbook.Sheets(NewWorkbook.Sheets.Count)
      Workbooks("CPTS Complete & Archived.xlsx").Save
      Workbooks("CPTS Complete & Archived.xlsx").Close
  End If
End Sub


Can someone tell me what I can do to make that work?
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Not sure if you wanted to continuously override the Workbook "CPTS Complete & Archived"? This will only add too it.

Code:
Sub poptart141()
'
Dim ws As Worksheet

For Each ws In ActiveWorkbook.Worksheets

    ws.Activate
    
Set ws = ActiveSheet
    
        If ws.Range("C3").Value = "Complete" Or ws.Range("C3").Value = "Archived" Then
        
            ws.Cells.Copy
            Workbooks.Open ("C:\Documents and Settings\username\Desktop\CPTS\CPTS Complete & Archived.xlsx")
            Sheets.Add
            ActiveSheet.Range("A1").Select
            ActiveSheet.Paste
            ActiveSheet.Move After:=Workbooks("CPTS Complete & Archived.xlsx").Sheets(Sheets.Count)
            Workbooks("CPTS Complete & Archived.xlsx").Close True

        End If
        
Next ws

End Sub
 
Upvote 0
Thanks for the reply, John!

I tried the code you provided, but nothing happens, still. I change C3 in any of the sheets in the current workbook to "Complete" or "Archived," and nothing happens. It just sits there. I really don't know why it's not doing anything at all... :confused:
 
Upvote 0

Forum statistics

Threads
1,214,596
Messages
6,120,438
Members
448,966
Latest member
DannyC96

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