I *think* this is the right section as it's a VBA issue, sorry if it's not!
So I'm tryign to get an excel file to open with all but certain worksheets hidden. I have found some code to make ONE sheet visible and all others hidden, and have tried to edit it to get the three I want to show by using 'or' in the If/Then statement, but it's still only showing one worksheet. Here.s the code I've got to: - Private Sub Workbook_Open()
-
Dim wsSheet As Worksheet
-
Application.ScreenUpdating = False
-
For Each wsSheet In Worksheets
-
If wsSheet.Name = "Allocations" Or wsSheet.Name = "Contact_Info" Or wsSheet.Name = "Mailout" Then
-
Else
-
wsSheet.Visible = False
-
End If
-
Next wsSheet
-
Application.ScreenUpdating = True
-
End Sub
Thanks for any help!
You do not event need the Iff...Else...End If Construct. Just a slight adjustment will do the trick for you: - Private Sub Workbook_Open()
-
Dim wsSheet As Worksheet
-
-
Application.ScreenUpdating = False
-
-
For Each wsSheet In Worksheets
-
With wsSheet
-
.Visible = (wsSheet.Name = "Allocations" Or wsSheet.Name = "Contact_Info" _
-
Or wsSheet.Name = "Mailout")
-
End With
-
Next wsSheet
-
-
Application.ScreenUpdating = True
-
End Sub
8 1387
Edit**: During your iteration you should do away with your Else statement and use If Not.
Example: - If Not wsSheet.Name = "Allocations" Or wsSheet.Name = "Contact_Info" Or wsSheet.Name = "Mailout" Then
-
wsSheet.Visible = False
-
End If
I'm getting a compile error with that? Saying it's expecting 'Then' or Goto'...
You do not event need the Iff...Else...End If Construct. Just a slight adjustment will do the trick for you: - Private Sub Workbook_Open()
-
Dim wsSheet As Worksheet
-
-
Application.ScreenUpdating = False
-
-
For Each wsSheet In Worksheets
-
With wsSheet
-
.Visible = (wsSheet.Name = "Allocations" Or wsSheet.Name = "Contact_Info" _
-
Or wsSheet.Name = "Mailout")
-
End With
-
Next wsSheet
-
-
Application.ScreenUpdating = True
-
End Sub
NeoPa 32,556
Expert Mod 16PB
NeoBrainless:
"I'm getting a compile error with that? Saying it's expecting 'Then' or Goto'..."
That's because Luk3r omitted the [ CODE ] tags when posting and you copied the code as it appeared - on separate lines, whereas it is, in fact, all on one (except the If ... & End If lines).
This only becomes clear when the [ CODE ] tags are used of course ;-)
NeoPa 32,556
Expert Mod 16PB
As for the question, there have already been some pointers on how your code might benefit from certain changes, yet I don't see why it wouldn't work in your original format. Certainly ADezii's suggestion is cleaner and to be recommended, but that's not to say yours shouldn't have worked.
In Access there's a nice Eval() function that gives a back-door to using SQL's In() construct, where you can specify a list of values, but it seems Excel doesn't support that one :-( (At least if it does the new versions obscure it well with their quite attrocious new web-based help systems - urghh).
@NeoPa - actually Luk3r's code is now different, the original used AndAlso which after it didn't work I did some research and realised (as he clearly did!) that AndAlso isn't a function in VBA...
I have made a workaround, but it's not pretty - I basically just said:
'Hide everything' then 'unhide these specific sheets'.
I'll have a play now with these other ideas and see which works best for me - I'd much rather a nice clean version!
Thanks for the tips everyone!
Ok, so Luk3r's new code partially works, but ONLY the 'Allocations' sheet is showing up, not any of the 'Or' sheets...
The code from ADezii does the trick very nicely, however. Think I'll go with that as it's MUCH neater than my current code! Thanks!
NeoPa 32,556
Expert Mod 16PB
I'm afraid Luk3r does seem to have a habit of posting "guessware". Unfortunate really. Their level of knowledge seems fairly basic ATM it seems.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: andrelamonde |
last post by:
After hours of searching, I can only find posts that tell me I'm coding
this situation correctly. I'm looking for more eyes to review this
code!
My Code (I've tried many listed variations of...
|
by: Dököll |
last post by:
I don't want you nice guys to waste your too much of your time, and confused me in the process.
I am hoping you can explain it to me like I am 2 years old, that's it.
Hoping to get a handle...
|
by: daveeboi |
last post by:
..I have been strugling to get this part of my site working correctly even though I can't see anything wrong with my code. I am trying to search a database and display paged results. But everytime...
|
by: audiokarate |
last post by:
I have like atleast 15 errors that say class, interface, or enum expected and I have no idea what that means. Can someone tell me what it is and how I might be able to fix it?
Thank you.
- Manny...
|
by: jonnyothan |
last post by:
The following code isn't producing expected results:
class Selectable
{
bool IsSelected() const;
};
class Unit : public Selectable
{
};
|
by: kirthi kumari |
last post by:
i donot find any errors,but for almost 18lines of the code am getting an error saying "class,interface or enum expected error".please look at the code below
package NQ;
import...
|
by: ngeywa |
last post by:
I am new in java and need your assistance. i have the code below which keep throwing error "class or interface expected".
public class Candidates
{
String candidateName;
String...
|
by: shathaaaa |
last post by:
hi every body here
i try to run program written in java (client server chat Application ) but when i try to compile it i get this error
" RMIChatServerImpl.java.java:6: calss,interface,or...
|
by: supriyakhankar |
last post by:
Hello friends,
I want to implement the ECDH key exchange algorithm. I have the code but i am getting the error as class or interface expected. please help me.
which packages i need to add and how...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |