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.
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.
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?
Apologies, done.Originally Posted by shg
Originally Posted by shg
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.
Oh, and the check box was made by the Control ToolboxOriginally 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.Originally Posted by shg
The code is in Module2
Don't know the difference between the two you mentioned.
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.
Thanks, shg. Works perfectly now
Bully for us!
You're welcome
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?
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks