Solved

Using Booleans globally in excel vba

Posted on 2007-03-27
2
243 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
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 …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

685 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