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


let's say i have some code as follows:


Code:
--------------------
If ComboReg.Value = "National" Then
ListNat.Visible = True
ListE.Visible = False
ListW.Visible = False
ListC.Visible = False
ListS.Visible = False
--------------------


is there any way to group the different lists so that i only need to
write .visible = false once? maybe something like
(liste,listw,listc,lists).visible = false.

what about for with-end with constructions? is there a way i can
write:


Code:
--------------------
with (liste,listw,listc,lists)
insert code
end with
--------------------


or something to that effect?

thanks.


--
dreamz
------------------------------------------------------------------------
dreamz's Profile: http://www.excelforum.com/member.php...o&userid=26462
View this thread: http://www.excelforum.com/showthread...hreadid=521145

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 227
Default minimizing redundant code

If you're toggling the visibility of a set of controls, you can put the
code in a Sub and call the Sub. The test that determines visibility
could be part of the Sub code, or you could set a flag before calling
the Sub to determine whether .visible is True or False.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default minimizing redundant code


Mark Lincoln Wrote:
If you're toggling the visibility of a set of controls, you can put the
code in a Sub and call the Sub. The test that determines visibility
could be part of the Sub code, or you could set a flag before calling
the Sub to determine whether .visible is True or False.

thanks for the reply. that would work, except that in my case, each
instance of the group of controls would have different visibility
properties, so i'd need to write them out anyway.

it's simple code. i was just wondering if there was a simpler way.


how about the second question? is there a simple way to format a group
of objects so that they all have the same format?


--
dreamz
------------------------------------------------------------------------
dreamz's Profile: http://www.excelforum.com/member.php...o&userid=26462
View this thread: http://www.excelforum.com/showthread...hreadid=521145

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default minimizing redundant code

Generally, you need to do a loop:

Dim myThing As Whatever

For Each myThing In WhateverCollection
myThing.Visible = False
Next myThing

That said, there isn't always a collection available, so you often need to improvise

Dim i As Integer

For i = 1 To 5
UserForm1.Controls("CheckBox" & i).Visible = False
Next i

And then you would need to pay attention to your naming conventions.


HTH,
Bernie
MS Excel MVP


"dreamz" wrote in message
...

let's say i have some code as follows:


Code:
--------------------
If ComboReg.Value = "National" Then
ListNat.Visible = True
ListE.Visible = False
ListW.Visible = False
ListC.Visible = False
ListS.Visible = False
--------------------


is there any way to group the different lists so that i only need to
write .visible = false once? maybe something like
(liste,listw,listc,lists).visible = false.

what about for with-end with constructions? is there a way i can
write:


Code:
--------------------
with (liste,listw,listc,lists)
insert code
end with
--------------------


or something to that effect?

thanks.


--
dreamz
------------------------------------------------------------------------
dreamz's Profile: http://www.excelforum.com/member.php...o&userid=26462
View this thread: http://www.excelforum.com/showthread...hreadid=521145



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 227
Default minimizing redundant code

is there a simple way to format a group
of objects so that they all have the same format?


At the risk of striking out completely... :)

I've occasionally created an array of control objects and used a
For-Next loop to set properties. I would flag a control to set its
property opposite to the others by setting an integer variable to the
array index of the control in question.

If you need to set one control of the group to visible and the rest to
not visible, you might keep track of which control is visible by
storing it in an object variable. When your situation changes, set the
visible control to not visible, then set the pertinent control to
visible and flag it as such.

I hope this helps a little bit.

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
Redundant data ale Excel Discussion (Misc queries) 1 May 14th 07 06:51 PM
minimizing problem Dave Excel Discussion (Misc queries) 5 June 7th 05 06:29 PM
Minimizing/Compressing VB Code in Excel File ... Joe HM Excel Programming 3 March 29th 05 01:51 PM
Minimizing application from VBA Steve Excel Programming 2 November 6th 03 03:46 PM
Minimizing a Form Khai[_2_] Excel Programming 1 July 24th 03 08:44 PM


All times are GMT +1. The time now is 06:01 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"