?
Solved

Using Booleans globally in excel vba

Posted on 2007-03-27
2
Medium Priority
?
247 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 describes a serious pitfall that can happen when deleting shapes using VBA.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

719 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