Macro to copy sheet to named file based on cell value

scarlett3

Board Regular
Joined
Jan 21, 2005
Messages
69
Hi

I have a file that has worksheets numbered 1-100 as well as a first worksheet entitled 'Summ'.

I would like to automate the following process via a macro:

For each worksheet, if the Q2 cell value is 'En_Pr', this worksheet is copied to the En_Pr.xlsx file which is already open. For any worksheet that has a Q2 cell value not equal to 'En_Pr', no action is taken.​

It would save me a lot of time to be able to do this via a macro rather than manually.

Can anyone help?

TIA
 

Some videos you may like

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows
VBA Code:
Sub t()
Dim sh As Worksheet, wb As Workbook
Set wb = Workbooks("En_Pr.xlsx")
    For Each sh In ThisWorkbook.Sheets
        If sh.Range("Q2").Value = "En_Pr" Then
            sh.Copy After:=wb.Sheets(wb.Sheets.Count)
        End If
    Next
End Sub
 
Solution

Watch MrExcel Video

Forum statistics

Threads
1,126,996
Messages
5,622,075
Members
415,875
Latest member
Tarali

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