View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Setting a public variable

In a General module (not behind a worksheet and not under the userform):

Public myLocked as boolean

Then you can just use that variable in any procedure--like the Ok button or the
Cancel button or wherever you want.

I wouldn't use Locked as a variable name. It looks way too close to a Range's
..Locked Property name. And it may not confuse VBA, but it could confuse me.

if me.optionbutton1.value = true then
mylocked = true
elseif me.optionbutton2.value = true then
mylocked = true
end if

Or you may be able to just look at the first and know (only two options and one
must be selected???):

if me.optionbutton1.value = true then
mylocked = true
else
mylocked = false
end if

or its equivalent:
mylocked = cbool(me.optionbutton1.value = true)


"Patrick C. Simonds" wrote:

On Userform1 I have 2 OptionButtons.

I need some way to set a public variable (called Locked) to true if
OptionButton1 is true when Userform1 closes or to false if OptionButton2 is
true


--

Dave Peterson