View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default Need Code To Run Always

You don't want that code to run all the time (that is why the programming
world moved to event driven processing, to get away from the enormous
overhead continually running code entailed). Because your code does
something based on the value in the cell name Total_Vol, you would use the
Change event procedure for the Input worksheet to monitor that value for
you. You would use code something like this...

Private Sub Worksheet_Change(ByVal Target As Range)
With Worksheets("Input")
If Not Intersect(Target, .Range("Total_Vol")) Is Nothing Then
If .Range("Total_Vol").Value < 500 Then
PT_Yes.Enabled = False
PT_No.Enabled = False
PT_No.Value = True
Else
PT_Yes.Enabled = True
PT_No.Enabled = True
PT_No.Value = False
End If
End If
End With
End Sub

and this code would be installed in the Input worksheet's code window. If
you are not familiar with how to do that, follow this procedure... right
click the Input worksheet's tab located at the bottom of the worksheet,
select View Code from the popup menu that appears and copy/paste the code
above into the code window that automatically opened when you did that.
Okay, from now on, when you change the value in Range("Total_Vol"), it will
set or unset the PT_Yes and PT_No controls according to the value entered.

--
Rick (MVP - Excel)


"BJ" wrote in message
...
How do I get code to run all the time? That is, not when an event occurs.
I
have the following code that I'd like to use ...

Sub Volume()
If Sheets("Input").Range("Total_Vol").Value < 500 Then
PT_Yes.Enabled = False
PT_No.Enabled = False
PT_No.Value = True
End Sub

Is it possible (a) to run the code - i.e. will the syntax work and (b) to
run the code as a constant check and not as an event? PT_Yes and PT_No
are
ActiveX OptionButtons.

Thanks for the help.