Form Control Text box

  • Thread starter Thread starter newguy
  • Start date Start date
N

newguy

I am trying to use a form control text box to hide tabs in a worksheet
and I cant seem to get it to work any suggestions.
Sub CheckBox_Click()
If ActiveSheet.CheckBoxes("Check Box 1").Value = 1 Then
Sheets("Sheet2").Visible = False
Else
Sheets("Sheet2").Visible = True
End If
End Sub
 
TextBox or CheckBox? Be sure your control name is correct:

"Check Box 1" and "CheckBox1" are two different names

CheckBoxes is not a collection, but OLEObjects is.

Or ActiveSheet.CheckBox1 = True will also work.
 
It works for me, but I had to rename it CheckBox1_Click.

It can also be reduced to

Sub CheckBox1_Click()
Sheets("Sheet2").Visible = ActiveSheet.CheckBoxes("Check Box 1").Value =
1
End Sub
 
Make sure your procedure is in a General module and assign your macro to the
checkbox.

Then you could modify your code so that it doesn't rely on the name of the
checkbox.

Option Explicit
Sub CheckBox_Click()
dim CBX as checkbox
set cbx = activesheet.checkboxes(application.caller)

if cbx.value = xlon then
worksheets("sheet2").visible = false
else
worksheets("Sheet2").visible = true
end if
end sub
 
Hi newguy

Try the below code, its working for me.

Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
Worksheets("Sheet2").Visible = True
Else
Worksheets("Sheet2").Visible = False
End If
End Sub
 
The error message I get is "Cannot run the macro 'Test.xlsm!
Sheet1.CheckBox_Click' The Macro may not be available in the workbook
or all macros may be disabled."

I checked the Trust center and allowed Macros to Run and it is in the
General Module.
 
You have to enable macros for macros to run.

And it looks like the current macro assigned to this checkbox is not in a
general module (or at least the pointer to the macro doesn't think so).

Rightclick on the checkbox (not really a textbox, right???) and reassign the
correct macro.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top