PDA

View Full Version : Solved: How To Set Global Parameter for macros based on the userform check box clicked



Hamond
01-11-2011, 12:04 PM
Hi

I have a useform containing checkboxes (called: Daily_Click, Weekly_Click, Monthly_click etc). Based on which checkbox is clicked, I want to set a global constant parameter that would feed into macros in the main module for a variable called "Freq".

So for example
If the UserForm1.checkbox daily_click = true then value for Freq = "D",
If the UserForm1.checkbox weekly_click = true then value for Freq = "W"

I then want to feed this constant variable into several macros such as the one below:


Sub Test()
Sheets("Transformed").select
Range("A3").Value = Freq & "1st Difference"
End sub


Is it possible to set Freq as a constant global variable depending on the checkbox that is ticked?

I have tried putting something like the following at the top of the module but I don't know how to make it conditional based on which checkbox is selected by the user in the userform.

If UserForm1.Daily_Click Then Const Freq = "D".

Hope someone can help as I'm really struggling to work out the best way to do this.

Thanks,

Hamond

Paul_Hossler
01-11-2011, 01:09 PM
In a standard module, I think all you'll need to do is use a Public varaible



Public Freq as String

Sub Test()
Sheets("Transformed").select
Range("A3").Value = Freq & "1st Difference"
End Sub



Paul

Bob Phillips
01-11-2011, 01:48 PM
Shouldn't they be option buttons, otherwise more than one could be clicked?

Hamond
01-11-2011, 03:01 PM
Yes, sorry these are indeed option boxes. If I decalre Public Freq As String, where in the code to I specify the value of Freq to pass on and the conditional select? i.e

If the UserForm1.checkbox daily_click = true then value for Freq = "D",
If the UserForm1.checkbox weekly_click = true then value for Freq = "W"

Does this go in the module or in the userform? Sorry new to using userforms so need some help.

Thanks,

Hamond

Bob Phillips
01-11-2011, 03:21 PM
Put it in the option button clicke events in the userform, but put the public variable in a standard module.

Hamond
01-11-2011, 03:41 PM
Got it. This seems to work.

Thanks for your help.