Macro to move all sheets containing the same text to another workbook

michellexlaiche

New Member
Joined
Mar 1, 2023
Messages
5
Office Version
  1. 2019
Platform
  1. Windows
Hello,

I'm trying to create a Macro that can find all sheets in my current workbook that contain the word "Closed" in cell J8, and collectively move them all to another workbook. I've figured out how to move one sheet (the active one) at at time but am struggling to move multiple ones.

From workbook: OPEN Order Status Reports
To workbook: CLOSED Order Status - 2023
Common cell is J8 that says Closed

Thank you for the help in advance!
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi and welcome to MrExcel

Put the following macro in the book that contains the sheets to move
Note: "CLOSED Order Status - 2023" This book must also be open

Note
: At least one sheet must remain in the book "OPEN Order Status Reports"

VBA Code:
Sub movesheets()
  Dim sh As Worksheet
  Dim wb As Workbook
 
  Set wb = Workbooks("CLOSED Order Status - 2023")  'This book must also be open
 
  For Each sh In ThisWorkbook.Sheets
    If sh.Range("J8").Value = "Closed" Then
      sh.Move After:=wb.Sheets(wb.Sheets.Count)
    End If
  Next
End Sub
 
Upvote 0
Thank you!

I ran it and got an error message of Type Mismatch for this line: If sh.Range("J8").Value = "Closed" Then

Any idea why that is?
 
Upvote 0

Forum statistics

Threads
1,223,703
Messages
6,173,977
Members
452,540
Latest member
haasro02

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