PDA

View Full Version : How to get the value of a checkbox when...



longyp
06-05-2011, 11:51 PM
you have to first calculate the name of the checkbox.

Hello Everyone

My checkbox is reference via

sheets("Cover Page").checkboxN.value (where N is a number starting at 1..)

Challenge is checkboxN needs to be determined - i.e. it could be Checkbox2, Checkbox3, Checkbox4 etc which I have done.

However

I have constructed a string (I tried variant too) containing the reference and tried passing this to the EVALUATE function but no matter how I construct the string, trim it etc EVALUATE always returns TYPE MISMATCH

Strangley if I type EVALUATE(Sheets("Cover Page").Checkbox1.value) in the immediate window I get a true/false response.

Any ideas? Am I making sense!

Thank you everyone

longyp
06-06-2011, 04:08 AM
Some code in case this inspires someone...thanks!

sNumber="1"

strString="sheets(""Cover Page"").chkAddon" & sNumber & ".value")

Evaluate(strString) 'This produces a type mismatch trying to workout the value of chkAddon1

Regards

Kenneth Hobs
06-06-2011, 09:44 AM
I am not sure why you need Evaluate.

MsgBox Worksheets("Sheet1").OLEObjects("chkAddon" & "1").Name, vbInformation, _
Worksheets("Sheet1").OLEObjects("chkAddon" & "1").Object.Value

longyp
06-06-2011, 10:17 AM
Thanks Ken. Works fine.

No reason to use Evaluate - my assumption this was the approach to use.

Thankyou very much.:thumb