Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Declaring Variables

I have a project with a couple of userforms and other modules. One of the
userforms applies a filter to a data list in Excel. Under certain criteria I
wish to remove the filter (ActiveSheet.ShowAllData) and to avoid this code
being executed when the fiter has not been applied (which produces an
error), I want to declare an integer variable which will be given one value
when the filter is applied and another value when removed. The value of this
integer would then determine whether to execute the ShowAllData code. My
questions a a) How and where do I declare this integer so that it is
available in all procedures applicable to the userform & b) what other
(easier?) way could this check be accomplished.

Any help much appreciated.
Regards
Chris Brunt



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Declaring Variables

Just trap the error

On Error Resume Next
ActiveSheet.ShowAllData
On Error goto 0

or check if the filter is applied

if ActiveSheet.AutofilterMode then _
ActiveSheet.ShowAllData


Regards,
Tom Ogilvy


"chris brunt" wrote in message
...
I have a project with a couple of userforms and other modules. One of the
userforms applies a filter to a data list in Excel. Under certain criteria

I
wish to remove the filter (ActiveSheet.ShowAllData) and to avoid this code
being executed when the fiter has not been applied (which produces an
error), I want to declare an integer variable which will be given one

value
when the filter is applied and another value when removed. The value of

this
integer would then determine whether to execute the ShowAllData code. My
questions a a) How and where do I declare this integer so that it is
available in all procedures applicable to the userform & b) what other
(easier?) way could this check be accomplished.

Any help much appreciated.
Regards
Chris Brunt





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 280
Default Declaring Variables

It is usually best to use an existing property or test the state of the
specific object in question when possible, as Tom has pointed out in his
response. To answer your first question, in cases where you need or want to
implement a "global" variable, declare such variable Public at the top of a
(standard) Module. It is in your own best interest to limit the use of
global variables and to limit the scope of variables to the minimum
necessary generally. A Boolean data type is the logical choice where the
variable will represent one of two states exclusively.

Example:
(at the top of a Module, not ClassModule, UserForm, etc., above any
procedure.)

Public gIsOn As Boolean

--
Bob Kilmer

"chris brunt" wrote in message
...
I have a project with a couple of userforms and other modules. One of the
userforms applies a filter to a data list in Excel. Under certain criteria

I
wish to remove the filter (ActiveSheet.ShowAllData) and to avoid this code
being executed when the fiter has not been applied (which produces an
error), I want to declare an integer variable which will be given one

value
when the filter is applied and another value when removed. The value of

this
integer would then determine whether to execute the ShowAllData code. My
questions a a) How and where do I declare this integer so that it is
available in all procedures applicable to the userform & b) what other
(easier?) way could this check be accomplished.

Any help much appreciated.
Regards
Chris Brunt





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Overflow error when declaring variables Jeff Excel Discussion (Misc queries) 2 January 9th 08 03:15 PM
Declaring variables in Module vs. Public Jeff Excel Discussion (Misc queries) 5 November 19th 07 08:27 PM
Declaring variables freekrill Excel Discussion (Misc queries) 2 July 19th 06 06:36 AM
Declaring variables freekrill Excel Discussion (Misc queries) 0 July 18th 06 06:15 PM
Declaring Global Variables skmr3 Excel Programming 1 July 14th 03 05:54 AM


All times are GMT +1. The time now is 06:39 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"