ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Array for clearing checkboxes (https://www.excelbanter.com/excel-programming/336915-array-clearing-checkboxes.html)

Richard

Array for clearing checkboxes
 
I have a number of checkboxes on my page, and when one is ticked, i am using
code to clear the others, and if the subject they relate to isn't relevant, i
hide them.
I have used arrays in the past to clear these in bulk.

Private Sub BlankCheckboxes(which)

'routine to specify whether checkboxes have a null value

Dim i As Long
For i = LBound(which, 1) To UBound(which, 1)
Me.Controls("Checkbox" & which(i)).Value = False
Next i
End Sub

Then:

Private Sub CheckBox1_Click()

If CheckBox1.Value = True Then
BlankCheckboxes Array(2, 3, 4)
End If
End Sub

When i try this i get Compile Error, Method or data member not found.

I know it worked before on another spreadsheet, am i missing something
obvious?

Help appreciated!

Richard

--
Richard

Tom Ogilvy

Array for clearing checkboxes
 
Your code worked fine for me when I had it all in the userform module.

The checkboxes are on a Userform?
--
Regards,
Tom Ogilvy

"Richard" wrote in message
...
I have a number of checkboxes on my page, and when one is ticked, i am

using
code to clear the others, and if the subject they relate to isn't

relevant, i
hide them.
I have used arrays in the past to clear these in bulk.

Private Sub BlankCheckboxes(which)

'routine to specify whether checkboxes have a null value

Dim i As Long
For i = LBound(which, 1) To UBound(which, 1)
Me.Controls("Checkbox" & which(i)).Value = False
Next i
End Sub

Then:

Private Sub CheckBox1_Click()

If CheckBox1.Value = True Then
BlankCheckboxes Array(2, 3, 4)
End If
End Sub

When i try this i get Compile Error, Method or data member not found.

I know it worked before on another spreadsheet, am i missing something
obvious?

Help appreciated!

Richard

--
Richard




Richard

Array for clearing checkboxes
 
Hi Tom, no they are on one of the sheets (the 3rd). Will this still work?
Will i have to reference the sheet (sheet3.checkbox)?
I was trying to avoid using a userform this time.

Richard

--
Richard


"Tom Ogilvy" wrote:

Your code worked fine for me when I had it all in the userform module.

The checkboxes are on a Userform?
--
Regards,
Tom Ogilvy

"Richard" wrote in message
...
I have a number of checkboxes on my page, and when one is ticked, i am

using
code to clear the others, and if the subject they relate to isn't

relevant, i
hide them.
I have used arrays in the past to clear these in bulk.

Private Sub BlankCheckboxes(which)

'routine to specify whether checkboxes have a null value

Dim i As Long
For i = LBound(which, 1) To UBound(which, 1)
Me.Controls("Checkbox" & which(i)).Value = False
Next i
End Sub

Then:

Private Sub CheckBox1_Click()

If CheckBox1.Value = True Then
BlankCheckboxes Array(2, 3, 4)
End If
End Sub

When i try this i get Compile Error, Method or data member not found.

I know it worked before on another spreadsheet, am i missing something
obvious?

Help appreciated!

Richard

--
Richard





Tom Ogilvy

Array for clearing checkboxes
 
Try it this way:

Private Sub BlankCheckboxes(which)

'routine to specify whether checkboxes have a null value

Dim i As Long
For i = LBound(which, 1) To UBound(which, 1)
Me.OleObjects("Checkbox" & which(i))Object..Value = False
Next i
End Sub

Then:

Private Sub CheckBox1_Click()

If CheckBox1.Value = True Then
BlankCheckboxes Array(2, 3, 4)
End If
End Sub

With the code in the sheet module.

--
Regards,
Tom Ogilvy


"Richard" wrote in message
...
Hi Tom, no they are on one of the sheets (the 3rd). Will this still work?
Will i have to reference the sheet (sheet3.checkbox)?
I was trying to avoid using a userform this time.

Richard

--
Richard


"Tom Ogilvy" wrote:

Your code worked fine for me when I had it all in the userform module.

The checkboxes are on a Userform?
--
Regards,
Tom Ogilvy

"Richard" wrote in message
...
I have a number of checkboxes on my page, and when one is ticked, i am

using
code to clear the others, and if the subject they relate to isn't

relevant, i
hide them.
I have used arrays in the past to clear these in bulk.

Private Sub BlankCheckboxes(which)

'routine to specify whether checkboxes have a null value

Dim i As Long
For i = LBound(which, 1) To UBound(which, 1)
Me.Controls("Checkbox" & which(i)).Value = False
Next i
End Sub

Then:

Private Sub CheckBox1_Click()

If CheckBox1.Value = True Then
BlankCheckboxes Array(2, 3, 4)
End If
End Sub

When i try this i get Compile Error, Method or data member not found.

I know it worked before on another spreadsheet, am i missing something
obvious?

Help appreciated!

Richard

--
Richard







Richard

Array for clearing checkboxes
 
Tom, i'm not sure if i'm doing this correctly, but i'm getting 'Expected End
of Statement' error before Object.Value

I took out one of the full stops between object and value as i assume this
was a typo.

--
Richard


"Tom Ogilvy" wrote:

Try it this way:

Private Sub BlankCheckboxes(which)

'routine to specify whether checkboxes have a null value

Dim i As Long
For i = LBound(which, 1) To UBound(which, 1)
Me.OleObjects("Checkbox" & which(i))Object..Value = False
Next i
End Sub

Then:

Private Sub CheckBox1_Click()

If CheckBox1.Value = True Then
BlankCheckboxes Array(2, 3, 4)
End If
End Sub

With the code in the sheet module.

--
Regards,
Tom Ogilvy


"Richard" wrote in message
...
Hi Tom, no they are on one of the sheets (the 3rd). Will this still work?
Will i have to reference the sheet (sheet3.checkbox)?
I was trying to avoid using a userform this time.

Richard

--
Richard


"Tom Ogilvy" wrote:

Your code worked fine for me when I had it all in the userform module.

The checkboxes are on a Userform?
--
Regards,
Tom Ogilvy

"Richard" wrote in message
...
I have a number of checkboxes on my page, and when one is ticked, i am
using
code to clear the others, and if the subject they relate to isn't
relevant, i
hide them.
I have used arrays in the past to clear these in bulk.

Private Sub BlankCheckboxes(which)

'routine to specify whether checkboxes have a null value

Dim i As Long
For i = LBound(which, 1) To UBound(which, 1)
Me.Controls("Checkbox" & which(i)).Value = False
Next i
End Sub

Then:

Private Sub CheckBox1_Click()

If CheckBox1.Value = True Then
BlankCheckboxes Array(2, 3, 4)
End If
End Sub

When i try this i get Compile Error, Method or data member not found.

I know it worked before on another spreadsheet, am i missing something
obvious?

Help appreciated!

Richard

--
Richard







Tom Ogilvy

Array for clearing checkboxes
 
Apparently there was a typo. It should be:

Me.OleObjects("Checkbox" & which(i)).Object.Value = False

--
Regards,
Tom Ogilvy

"Richard" wrote in message
...
Tom, i'm not sure if i'm doing this correctly, but i'm getting 'Expected

End
of Statement' error before Object.Value

I took out one of the full stops between object and value as i assume this
was a typo.

--
Richard


"Tom Ogilvy" wrote:

Try it this way:

Private Sub BlankCheckboxes(which)

'routine to specify whether checkboxes have a null value

Dim i As Long
For i = LBound(which, 1) To UBound(which, 1)
Me.OleObjects("Checkbox" & which(i))Object..Value = False
Next i
End Sub

Then:

Private Sub CheckBox1_Click()

If CheckBox1.Value = True Then
BlankCheckboxes Array(2, 3, 4)
End If
End Sub

With the code in the sheet module.

--
Regards,
Tom Ogilvy


"Richard" wrote in message
...
Hi Tom, no they are on one of the sheets (the 3rd). Will this still

work?
Will i have to reference the sheet (sheet3.checkbox)?
I was trying to avoid using a userform this time.

Richard

--
Richard


"Tom Ogilvy" wrote:

Your code worked fine for me when I had it all in the userform

module.

The checkboxes are on a Userform?
--
Regards,
Tom Ogilvy

"Richard" wrote in message
...
I have a number of checkboxes on my page, and when one is ticked,

i am
using
code to clear the others, and if the subject they relate to isn't
relevant, i
hide them.
I have used arrays in the past to clear these in bulk.

Private Sub BlankCheckboxes(which)

'routine to specify whether checkboxes have a null value

Dim i As Long
For i = LBound(which, 1) To UBound(which, 1)
Me.Controls("Checkbox" & which(i)).Value = False
Next i
End Sub

Then:

Private Sub CheckBox1_Click()

If CheckBox1.Value = True Then
BlankCheckboxes Array(2, 3, 4)
End If
End Sub

When i try this i get Compile Error, Method or data member not

found.

I know it worked before on another spreadsheet, am i missing

something
obvious?

Help appreciated!

Richard

--
Richard









Richard

Array for clearing checkboxes
 
Thanks Tom. All is working well now. Appreciate the help.
--
Richard


"Tom Ogilvy" wrote:

Apparently there was a typo. It should be:

Me.OleObjects("Checkbox" & which(i)).Object.Value = False

--
Regards,
Tom Ogilvy

"Richard" wrote in message
...
Tom, i'm not sure if i'm doing this correctly, but i'm getting 'Expected

End
of Statement' error before Object.Value

I took out one of the full stops between object and value as i assume this
was a typo.

--
Richard


"Tom Ogilvy" wrote:

Try it this way:

Private Sub BlankCheckboxes(which)

'routine to specify whether checkboxes have a null value

Dim i As Long
For i = LBound(which, 1) To UBound(which, 1)
Me.OleObjects("Checkbox" & which(i))Object..Value = False
Next i
End Sub

Then:

Private Sub CheckBox1_Click()

If CheckBox1.Value = True Then
BlankCheckboxes Array(2, 3, 4)
End If
End Sub

With the code in the sheet module.

--
Regards,
Tom Ogilvy


"Richard" wrote in message
...
Hi Tom, no they are on one of the sheets (the 3rd). Will this still

work?
Will i have to reference the sheet (sheet3.checkbox)?
I was trying to avoid using a userform this time.

Richard

--
Richard


"Tom Ogilvy" wrote:

Your code worked fine for me when I had it all in the userform

module.

The checkboxes are on a Userform?
--
Regards,
Tom Ogilvy

"Richard" wrote in message
...
I have a number of checkboxes on my page, and when one is ticked,

i am
using
code to clear the others, and if the subject they relate to isn't
relevant, i
hide them.
I have used arrays in the past to clear these in bulk.

Private Sub BlankCheckboxes(which)

'routine to specify whether checkboxes have a null value

Dim i As Long
For i = LBound(which, 1) To UBound(which, 1)
Me.Controls("Checkbox" & which(i)).Value = False
Next i
End Sub

Then:

Private Sub CheckBox1_Click()

If CheckBox1.Value = True Then
BlankCheckboxes Array(2, 3, 4)
End If
End Sub

When i try this i get Compile Error, Method or data member not

found.

I know it worked before on another spreadsheet, am i missing

something
obvious?

Help appreciated!

Richard

--
Richard











All times are GMT +1. The time now is 12:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com