+ Reply to Thread
Results 1 to 10 of 10

Turning On a Checkbox

  1. #1
    Registered User
    Join Date
    08-27-2003
    Location
    Melbourne, Australia
    Posts
    75

    Turning On a Checkbox

    Hi, I want to turn on (tick) a check box from within a macro.

    I tried

    Please Login or Register  to view this content.

    but I get Runtime Error 424 - Object required.

    Is there a way to do this?

    Cheers, Paul.
    Last edited by Paul Edwards; 04-14-2008 at 12:16 AM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Please edit your post to add code tags.

    Are these checkboxes on the sheet from the Control Toolbox, or checkboxes on a form?

    Where does the code reside?

  3. #3
    Registered User
    Join Date
    08-27-2003
    Location
    Melbourne, Australia
    Posts
    75
    Quote Originally Posted by shg
    Please edit your post to add code tags.
    Apologies, done.

    Quote Originally Posted by shg
    Are these checkboxes on the sheet from the Control Toolbox, or checkboxes on a form?
    Where does the code reside?

    I have a macro ("ClearData") which is run from a Command Button that basically clears data and resets defaults.

    On sheet 2 I have the Option
    "Turn Check Box on by Default" (Yes/No)

    The macro checks the value in sheet 2 and if "Yes", it is meant to turn on the CheckBox.

    Not such a hard job I would'a thought...

    Hope this makes it clear.

  4. #4
    Registered User
    Join Date
    08-27-2003
    Location
    Melbourne, Australia
    Posts
    75
    Quote Originally Posted by shg
    Are these checkboxes on the sheet from the Control Toolbox, or checkboxes on a form?
    Oh, and the check box was made by the Control Toolbox

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Paul,

    Is the code running in a sheet module or a code module?

  6. #6
    Registered User
    Join Date
    08-27-2003
    Location
    Melbourne, Australia
    Posts
    75
    Quote Originally Posted by shg
    Paul,

    Is the code running in a sheet module or a code module?
    Sorry, you're testing my basic VB/Excel knowledge here.

    The code is in Module2

    Don't know the difference between the two you mentioned.

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    So in a code module, CheckBox1 is not a known variable name; its scope is within the sheet than contains it.

    So you could reference CheckBox1 in a Sheet module, but in a code module it must be qualified by the sheet codename, e.g., Sheet1.CheckBox1, where Sheet1 is the codename (not necessarily the sheet name) of the sheet on which the checkbox appears.

    If you look in the Project Explorer window, sheet codenames are shown first, followed by the sheet names in parens. Again, you want the codename for this reference.

    And you can abbreviate your code to
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    08-27-2003
    Location
    Melbourne, Australia
    Posts
    75
    Thanks, shg. Works perfectly now

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Bully for us!

    You're welcome

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    BTW, here's a tip. The VBE's Intellisense mechanism has an autocomplete function. If you type in the first few characters of something (like a variable name, property, or method, then type Ctrl+Space, you see a list of options.

    On a Sheet module, you could have typed Check (Ctrl+Space) and seen CheckBox1 as an option.

    In a code module, you could have typed Sheet1.Check (Ctrl+Space) and seen CheckBox1 as an option.

    In a code module, if you typed Check (Ctrl+Space) you'd have seen nothing, which is a good hint Excel hasn't a clue what you're after -- as here.

    Capisce?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1