VBA instr function help

anguschanch

New Member
Joined
Jun 16, 2014
Messages
45
Hi, I am new to VBA.

My task is to copy all relevant worksheets into a new workbook. The name of the worksheets are stored in a worksheet called "Team list".
I don't know whats wrong with my code. Can someone save me please??

If Err.Number = 0 Then
For Each Worksheet In Worksheets
If InStr(1, Worksheet.Name, Worksheets("Team list").Range("A1").Value) > 0 Then
Worksheet.Select (False)
End If
If InStr(1, Worksheet.Name, Worksheets("Team list").Range("A2").Value) > 0 Then
Worksheet.Select (False)
End If
Next Worksheet
ActiveWindow.SelectedSheets.Copy
End If



PS. what is the purpose of the line saying if err.number = 0? (i just copy it from previous designer)
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
So, you only want to copy certain sheets over? Based on the name of the sheet? and whether the name is in a list? So, the list looks like A1: Sheet A, A2: Sheet B, A3: Sheet D, so, sheets named Sheet A, Sheet B and Sheet D would get copied because their names are in this list?
 
Upvote 0
Thanks for ur reply
i want to copy worksheets based on their names and i got the required worksheets saved in another worksheet in "Team list".
 
Upvote 0

Forum statistics

Threads
1,215,494
Messages
6,125,145
Members
449,207
Latest member
VictorSiwiide

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