I've got a simple piece of code in Excel VBA which is:
Code:
Sub CheckBox1_Click()
If CheckBox1.Value = True Then
Range("A1").Value = 1
Else
Range("A1").Value = 0
End If
End Sub
which is supposed to make 1 or 0 appear in cell A1 depending on whether or not a checkbox is ticked. However all I get is the error message 'Runtime error 424. Object required'.
I don't know what this means or why the code doesn't work and I can't find anything in Excel Help which explains what's wrong!
Anyone help?
Cheers
-Rob
Last edited by TheRobster; Nov 12th, 2004 at 08:56 AM.
I think you misunderstood what it was that I'm trying to do. I know the checkbox doesn't actually reside in a cell, but what I want it to do is to be linked to cell so that when it is ticked/unticked (true/false) then this places the number 1 or 2 in cell A1.
This isn't what I want it to do in my spreadsheet exactly. What I want is for a range of cells to be coloured green or white, depending on the checkbox condition. So in English the code would read:
If CheckBox1 is ticked then
Cell A1 colour = green
If CheckBox1 is not ticked then
Cell A1 colour = white
I have the code behind Sheet1. That may be the issue if you have
the code in the ThisWorkBook or a module. Reference the
workbook/worksheet before the checkbox.
HTH
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Did you use an ActiveX control? I was using the Forms checkbox - this is the only difference as far as I can see between what I did and what you did, only yours works and mine doesn't.
this is an old thread from 2004 and the people who were posting here may well no longer visit this forum, you should have started a new thread
i do not have office 2019, but i guess you should look in the developer tab >controls
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete