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)
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)