Consulting

Results 1 to 4 of 4

Thread: How to get the value of a checkbox when...

  1. #1
    VBAX Newbie
    Joined
    Jun 2011
    Posts
    5
    Location

    How to get the value of a checkbox when...

    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

  2. #2
    VBAX Newbie
    Joined
    Jun 2011
    Posts
    5
    Location
    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

  3. #3
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    I am not sure why you need Evaluate.

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

  4. #4
    VBAX Newbie
    Joined
    Jun 2011
    Posts
    5
    Location
    Thanks Ken. Works fine.

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

    Thankyou very much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •