VBA code not skipping worksheet

sjesiono

New Member
Joined
Jun 20, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
We have a macro that updates old files to a newer format. Part of the macro is supposed to pull over any worksheets from the old file that do not already exist in the new one, while ignoring two outdated sheets that we don't want to use anymore. The macro correctly skips over "Instructions" but is not skipping over "Dummy." I can't figure out what I'm missing here.

VBA Code:
Sub WSMove()
    Dim ws As Worksheet
    Dim nm As name
    Dim found
    Dim name
    For Each ws In Workbooks("old.xlsm").Worksheets
    found = False
    
    name = ws.name
    If name <> "Instructions" Or name <> "Dummy" Then
        For Each nws In Workbooks("New.xlsm").Worksheets
            If name = nws.name Then
                found = True
            End If
        Next nws
        
        If found = False Then
            Workbooks("new.xlsm").Sheets.Add(After:=Workbooks("new.xlsm").Sheets(Workbooks("new.xlsm").Sheets.count)).name = name
            If Workbooks("old.xlsm").Sheets(name).FilterMode Then Workbooks("old.xlsm").Sheets(name).ShowAllData
            Workbooks("old.xlsm").Sheets(name).Cells.Copy
            Workbooks("new.xlsm").Worksheets(name).Range("A1").PasteSpecial xlPasteValues
            Workbooks("new.xlsm").Worksheets(name).Range("A1").PasteSpecial xlPasteColumnWidths
            Workbooks("new.xlsm").Worksheets(name).Range("A1").PasteSpecial xlPasteFormats
            Workbooks("new.xlsm").Worksheets(name).Cells.Locked = True
            Workbooks("new.xlsm").Worksheets(name).Protect
        End If
    End If
    Next ws
End Sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Try:
VBA Code:
If name <> "Instructions" And name <> "Dummy" Then
Using OR when checking the Dummy sheet still means it's not "Instructions", which results in True, making the whole statement: If TRUE Or FALSE Then

TRUE Or FALSE = TRUE
TRUE And FALSE = FALSE
 
Upvote 0
Solution

Forum statistics

Threads
1,224,518
Messages
6,179,256
Members
452,901
Latest member
LisaGo

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