PDA

View Full Version : passing arguments to forms???



greg2935
12-02-2008, 09:54 AM
Hi,

This must be simple but I've not got a glue how to do it. I have a load (40+) checkboxes that essentially do the same thing but with different parameters. Obviously, I would like to pass the various parameters to one function which would save a lot of typing. I can pass some arguments such as a range using


somefunction(D26)

function somefunction(somerange as range)
sheets("Sheet1").range(somerange).Select
end function


or whatever, but I cannot find the correct type to pass the name of the checkbox such as:


somefunction(D26, checkbox1)

function somefunction(somerange as range, thecheckbox as checkbox)
If myForm.thecheckbox.Value = True Then
Sheets("Sheet1").range(somerange).Value = True
End If
end function


I've tried types Range, Name, Names etc and dont seem to be able to find the correct method. Any help?

Greg

Bob Phillips
12-02-2008, 10:28 AM
Where is the somefunction, in the userform module, or a standard code module?

Bob Phillips
12-02-2008, 10:31 AM
ACtually, I don't think it matters.



Function somefunction(somerange As Range, thecheckbox As MSForms.CheckBox)
If thecheckbox.Value = True Then
Sheets("Sheet1").Range(somerange).Value = True
End If
End Function