Macro to copy sheet to named file based on cell value

scarlett3

Board Regular
Joined
Jan 21, 2005
Messages
73
Office Version
  1. 365
Platform
  1. Windows
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
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
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
 
Upvote 0
Solution

Forum statistics

Threads
1,214,583
Messages
6,120,378
Members
448,955
Latest member
BatCoder

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