![]() |
Form Control Text box
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 |
Form Control Text box
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. "newguy" wrote in message ... 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 |
Form Control Text box
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 -- __________________________________ HTH Bob "newguy" wrote in message ... 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 |
Form Control Text box
It is a check box and the I right click on the check box the name is
Check Box 1. |
Form Control Text box
The Checkboxes collection are for checkboxes from the Forms toolbar.
JLGWhiz wrote: 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. "newguy" wrote in message ... 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 -- Dave Peterson |
Form Control Text box
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 newguy wrote: 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 -- Dave Peterson |
Form Control Text box
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 "newguy" wrote: 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 |
Form Control Text box
Actually, the code seems to work for me. Are you getting any error messages
with it? "newguy" wrote in message ... 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 |
Form Control Text box
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. |
Form Control Text box
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. newguy wrote: 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. -- Dave Peterson |
All times are GMT +1. The time now is 03:45 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com