I am trying to create a macro in order to be able to retrieve all sheets in a workbook. Here is a "loop through all" code I used. The problem is that I want to exclude 1 of the sheets from retrieval. How can I modify the following code to be able achieve that? The sheet I would like to exclude from the loop is called "Lookup" oe Sheet 1. Please help. Thanks.
Declare Function EssMenuVRetrieve Lib "ESSEXCLN.XLL" () As Long
Num_Sheets = Application.Sheets.Count
For y = 1 To Num_Sheets
x = EssMenuVRetrieve
If Sheets(y).Name <> "Lookup" or _
sheets (y).Name <> "Test" Then
Think about the logic of that statement for a second.
If the sheet name is Test then it is <> Lookup so the If is true
If sheet name is Lookup then it is <> Test so again it will be true
If sheet name is anything else then it will be <> Test And <> Lookup so it will again be true
I can't tell what you are trying to exclude here btu your code will nto exclude anything. If those 2 sheets are the ones you want to exclude then the proper logic would be.
If Not Sheets(y).Name = "Lookup" And _
Not sheets (y).Name = "Test" Then