Solved

Using Booleans globally in excel vba

Posted on 2007-03-27
2
241 Views
Last Modified: 2010-04-30
I am trying to set up a boolean 'HideRows' globally. Within the 'Summary' tab, CodeB hides all of the empty rows when that worksheet is activated. I don't want that code activated until after 'CodeA' is run. So what I did below is set up HideRows = False and then after CodeA is run, I set HideRows = True.
Then, in the Worksheet's code, I have an if statement saying that if HideRows = True then execute CodeB

Public HideRows As Boolean
HideRows = False
Sub CodeA
HideRows = True

'Summary Worksheet Code
Private Sub Worksheet_Activate()
If HideRows = True Then
        Execute CodeB
End if
End Sub

What am I doing wrong?
0
Comment
Question by:tiehaze
2 Comments
 

Author Comment

by:tiehaze
ID: 18804083
For clarification, the problem that I am having is in:

'Summary Worksheet Code
Private Sub Worksheet_Activate()
If HideRows = True Then
        Execute CodeB
End if
End Sub

It isn't executing CodeB and therefor must not be recognizing HideRows as true
0
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 500 total points
ID: 18804167
Place this code in your worksheet module:

Public HideRows As Boolean

Private Sub Worksheet_Activate()
   If HideRows Then CodeB
End Sub

The other code should look like:

   CodeA
   Sheets("Summary").HideRows = True

Kevin
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Office 2016 without internet 6 38
Excel VBA - UserForm Label Caption to show recordset data dynamically 12 19
Excel IF formula 3 20
Unhide very hidden sheets with password 22 44
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question