VBA Express Forum  




Go Back   VBA Express Forum > VBA Code & Other Help > Excel Help
     Feedback     
Register FAQ Members Arcade Knowledge Base Training Articles Consulting

Reply
 
Thread Tools Display Modes
Old 04-30-2012, 09:35 AM   #1
AIDSNGO

 
Joined: Apr 2012
Posts: 15
Kb Entries: 0
Articles: 0
Worksheet_calculate runs based on every formula in sheet

I am trying to hide several rows whenever the option button "no" is checked in a groupbox in a spreadsheet. I could not get any code to run when the option buttons were checked, so I set the cell link to R27 and then put into R26 the formula =R27. This seems to work with the code below, but the spreadsheet is constantly updating, with lots of spinning cursors and eventual freezing. Is there a simple fix, or a more direct method than my workaround?

Thanks!

AIDSNGO

VBA:
Private Sub Worksheet_Calculate() Dim target As Range Set target = Range("R26") If target.Value = "2" Then Rows("35:68").EntireRow.Hidden = True End If End Sub
VBA tags courtesy of www.thecodenet.com

Local Time: 09:12 PM
Local Date: 06-17-2013
Location:

 
Reply With Quote Top
Old 04-30-2012, 01:13 PM   #2
p45cal

 
Joined: Oct 2005
Posts: 1,772
Kb Entries: 0
Articles: 0
Are these activeX optionbuttons, or the other kind?
Excel Version?
If they're activeX then in design mode if you double click one it'll take you to it's click event code. Change it from the likes of:
Private Sub OptionButton1_Click()
to:
VBA:
Private Sub OptionButton1_Change() Rows("35:68").EntireRow.Hidden = ActiveSheet.OptionButton1 End Sub
VBA tags courtesy of www.thecodenet.com

If the option buttons are of the other type then if you right-click it you get the opportunity to assign a macro. Presumably you also have another option button to switch the other way. Both these option buttons need to assigned to the same macro which should be like:
VBA:
Sub OptionButton1_Click() Rows("35:68").EntireRow.Hidden = (ActiveSheet.OptionButtons("Option Button 1").Value = 1) End Sub
VBA tags courtesy of www.thecodenet.com
Obviously the codes should be adjusted to reflect the actual names of the option buttons.
You don't need to link any cells, nor any calculate_event code.


p45cal - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

Local Time: 05:12 AM
Local Date: 06-18-2013

 
Reply With Quote Top
Old 05-01-2012, 03:22 AM   #3
snb

 
Joined: Apr 2012
Posts: 1,191
Kb Entries: 0
Articles: 4
If the groupbox contains 2 optionbuttons (yes & No) you'd better use a checkbox:

VBA:
Private Sub checkbox1_change() Rows("35:68").EntireRow.Hidden = checkbox1.value End Sub
VBA tags courtesy of www.thecodenet.com

Local Time: 07:12 AM
Local Date: 06-18-2013

 
Reply With Quote Top
Old 05-01-2012, 03:44 AM   #4
xld
 
xld's Avatar
Distinguished Lord of VBAX

 
Joined: Apr 2005
Posts: 23,118
Kb Entries: 3
Articles: 2
You don't need Entirerow when you use the Rows object, Rows is the entirerow

VBA:
Rows("35:68").Hidden = ...
VBA tags courtesy of www.thecodenet.com


____________________________________________
Nihil simul inventum est et perfectum

Abusus non tollit usum

Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber

Local Time: 06:12 AM
Local Date: 06-18-2013
Location:

 
Reply With Quote Top
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -7. The time now is 10:12 PM.


Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright © 2004 - 2012 VBA Express