Only run if check box is checked

  • Follow


I have some code that I only want to be run if a check box is checked. So I 
inserted an ActiveX check box which I have named cbRecord.

I then put the following IF around the code which is initiated by clicking a 
spinner form control:

If cbRecord.Value Then
....
....
....
End If

However, when the code is run I get the following error: Run time error 
'424': Object required. When I go to debug, the code doesn't even know that 
my check box exists.

TIA...Geoff

0
Reply Utf 1/26/2010 9:56:19 PM

Try

If Sheets("Sheet1").CheckBoxes("Check Box 1").Value = xlOn Then
   'do stuff
End If
-- 
Cheers,
Ryan


"Geoff" wrote:

> I have some code that I only want to be run if a check box is checked. So I 
> inserted an ActiveX check box which I have named cbRecord.
> 
> I then put the following IF around the code which is initiated by clicking a 
> spinner form control:
> 
> If cbRecord.Value Then
> ...
> ...
> ...
> End If
> 
> However, when the code is run I get the following error: Run time error 
> '424': Object required. When I go to debug, the code doesn't even know that 
> my check box exists.
> 
> TIA...Geoff
> 
0
Reply Utf 1/26/2010 10:19:01 PM


or even tighter (since we know the name of the ActiveX checkbox):

   If Sheets("Sheet1").cbRecord then
      'do stuff
   End if

"Ryan H" wrote:

> Try
> 
> If Sheets("Sheet1").CheckBoxes("Check Box 1").Value = xlOn Then
>    'do stuff
> End If
> -- 
> Cheers,
> Ryan
> 
> 
> "Geoff" wrote:
> 
> > I have some code that I only want to be run if a check box is checked. So I 
> > inserted an ActiveX check box which I have named cbRecord.
> > 
> > I then put the following IF around the code which is initiated by clicking a 
> > spinner form control:
> > 
> > If cbRecord.Value Then
> > ...
> > ...
> > ...
> > End If
> > 
> > However, when the code is run I get the following error: Run time error 
> > '424': Object required. When I go to debug, the code doesn't even know that 
> > my check box exists.
> > 
> > TIA...Geoff
> > 
0
Reply Utf 1/26/2010 10:33:01 PM

Thanks Ryan. Now I get: Run time error '1004': Unable to get the Checkboxes 
property of the Worksheet class.

There's nothing in the Locals window.

"Ryan H" wrote:

> Try
> 
> If Sheets("Sheet1").CheckBoxes("Check Box 1").Value = xlOn Then
>    'do stuff
> End If

0
Reply Utf 1/26/2010 10:33:02 PM

Many thanks. That worked. I don't know what I was doing wrong. I basically 
copied the code from another spreadsheet I made a ways back. And it still 
works there. VBA in Excel is still pretty mysterious to me and not nearly as 
easy as Access for me.

"B Lynn B" wrote:

> or even tighter (since we know the name of the ActiveX checkbox):
> 
>    If Sheets("Sheet1").cbRecord then
>       'do stuff
>    End if
> 
> "Ryan H" wrote:
> 
> > Try
> > 
> > If Sheets("Sheet1").CheckBoxes("Check Box 1").Value = xlOn Then
> >    'do stuff
> > End If
> > -- 
> > Cheers,
> > Ryan
> > 
> > 
> > "Geoff" wrote:
> > 
> > > I have some code that I only want to be run if a check box is checked. So I 
> > > inserted an ActiveX check box which I have named cbRecord.
> > > 
> > > I then put the following IF around the code which is initiated by clicking a 
> > > spinner form control:
> > > 
> > > If cbRecord.Value Then
> > > ...
> > > ...
> > > ...
> > > End If
> > > 
> > > However, when the code is run I get the following error: Run time error 
> > > '424': Object required. When I go to debug, the code doesn't even know that 
> > > my check box exists.
> > > 
> > > TIA...Geoff
> > > 
0
Reply Utf 1/26/2010 11:25:01 PM

I think I figured it out. The code was in a generic module and not in the 
module for the specific worksheet.

"Geoff" wrote:

> Many thanks. That worked. I don't know what I was doing wrong. I basically 
> copied the code from another spreadsheet I made a ways back. And it still 
> works there. VBA in Excel is still pretty mysterious to me and not nearly as 
> easy as Access for me.

0
Reply Utf 1/27/2010 12:18:01 AM

5 Replies
1660 Views

(page loaded in 0.288 seconds)

Similiar Articles:
















7/18/2012 2:59:36 PM


Reply: