if VBA

Hi,

My below snippet of code copys data from sheets and pastes into another workbook.

I want to add a line to say

if sheet = "sheet1" or "Control" do not copy - basically skip to the next sheet

Thanks
Seamus

Sub SaveShtsAsBook_Sector_Booked()
    Dim Sheet As Worksheet, SheetName$, MyFilePath$, N&
    MyFilePath$ = ActiveWorkbook.Path & "\" & _
    Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 4)
    With Application
        .ScreenUpdating = False
        .DisplayAlerts = False
         '      End With
        On Error Resume Next '<< a folder exists
        MkDir MyFilePath '<< create a folder
        
'        Sheets("Sheet1").Select
'    ActiveWindow.SelectedSheets.Visible = False
        
        Sheets("Sheet1").Select
    ActiveSheet.ShowAllData
        
        For N = 1 To Sheets.Count
            Sheets(N).Activate
            SheetName = ActiveSheet.Name
            Cells.Copy
            
               
      Workbooks.Open Filename:= _
        ""
            
            'Workbooks.Add (xlWBATWorksheet)

Open in new window

Seamus2626Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
Hi,

Not knowing the rest of your code

For Each sh In Sheets
            If sh.Name <> "Sheet1" And sh.Name <> "Control" Then
                Sheets(sh.Index).Activate
                SheetName = ActiveSheet.Name
                ' Rest of your code
            End If
        Next

Open in new window

Regards

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Seamus2626Author Commented:
Thanks Rgonzo!
aikimarkCommented:
recommendations
1. use direct assignment of values rather than the clipboard
Example in my article: http://www.experts-exchange.com/articles/2253/Fast-Data-Push-to-Excel.html

2. If you use direct assignment, you do not need to activate the worksheets

3. I'm a proponent of For Each...Next loops when iterating objects as shown in Rgonzo's code.

Alternative exclusion code examples:
If sh.Name = "Sheet1" Or sh.Name = "Control" Then
Else
     'data movement code
End If

Open in new window

'may be less reliable
If Instr(1, "Sheet1^Control", sh.Name, vbTextCompare) <> 0 Then
     'data movement code
End If

Open in new window

'more reliable than above example
If Instr(1, "^Sheet1^Control^", "^" & sh.Name & "^", vbTextCompare) <> 0 Then
     'data movement code
End If

Open in new window

Select Case UCase(sh.Name)
    Case "SHEET1", "CONTROL"
     'data movement code
End Select

Open in new window

Dim oDic As Object
Set oDic = CreateObject("Scripting.Dictionary")
oDic.CompareMode = 1      '1=vBTextCompare 
oDic("Sheet1") = 1
oDic("Control") = 1


If oDic.Exists(sh.Name) Then
Else
     'data movement code
End Select

Open in new window

Seamus2626Author Commented:
Thanks for the adds aikimark!!
aikimarkCommented:
Thanks for the adds aikimark!!
You're welcome.  When closing your questions, you can select multiple comments if more than one is helpful.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.