View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Brian Brian is offline
external usenet poster
 
Posts: 49
Default Simple hiding columns with vba does not work with a checkbox

Hello,

I am a little confused by something that should be very
simple. I am trying to have certain columns hide and
unhide depending on if a check box is check or not checked.
I get an error that says:
"Run-time error 1004"
"Unable to set the Hidden Property of the Range class"

What confuses me most is the following works when placed
in a subroutine but not when placed in a checkbox's change
function.

So this works:

Sub test()
Columns("A:B").Hidden = Not Columns("A:B").Hidden
End Sub

And this doesn't:

Private Sub CheckBox1_Click()
Columns("A:B").Hidden = Not Columns("A:B").Hidden
End Sub

This is all on a blank new workbook with nothing else to
get in the way and I am using Excel 97. The worksheet is
not protected and I get the same results when there is
data in the cells and when there is no date in the cells.
I have also tried included more specific references with
workbooks(). and worksheets(). but that doesn't help
either. Any help would be much appreciated as I am about
to head butt my computer.

Thanks,

Brian