Make a check box run a macro

M

Miguel

Hello,
I want a check box run a macro. Basically what I want to do is if the check
box is cheked then some columns become unhide. If the checkbox is not checked
then the columns remain hide. The check box is on the "Main Input" and the
columns hidden or not are on the "Summary" worksheet. This is what I wrote so
far:

Sheets("Summary").Select
Columns("AS:BA").Select
Selection.EntireColumn.Hidden = False
Range("A1").Select
Sheets("Main Input").Select
End Sub

Thanks
Miguel
 
F

FSt1

hi
try this
Private Sub CheckBox1_Click()
If CheckBox1.Value = ture Then
Sheets("Summary").Columns("AS:BA").EntireColumn.Hidden = False
Else
Sheets("Summary").Columns("AS:BA").EntireColumn.Hidden = True
End If
End Sub
i eliminated all the selecting and flopping back and forth from sheet to
sheet.
that is really not needed.

Regards
FSt1
 
M

Miguel

Hi,
I use the code below, but the code
If CheckBox1.Value = True Then
gets highlighted and there's a error message "object required". What can I
do to fix the problem?

Miguel
 
F

FSt1

hi
assumming you are using a active X checkbox from the control tool box...
in design mode, right click the check box and from the popup click view code.
sub checkbox1_click() will default in. past the code into to the sub.
techniqually this is more sheet code in that the check box is assigned to the
sheet. it does not go in a standard module.

regards
FSt1
 
F

FSt1

hi
if you do have the code in a standard module, VB can't find the
checkbox.(object required) once you put it in the check box code, it should
works. it works for me.

regards
FSt1
 

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

Top