Solved

Using Booleans globally in excel vba

Posted on 2007-03-27
2
242 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

840 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