MrExcel Publishing
Your One Stop for Excel Tips & Solutions


Posted by Nick on July 09, 2001 11:34 AM

I am trying to write a macro to hide a column if particular data is found in it.
I have tried using either

Columns(curCol).Hidden = True
Cells(row1, curCol).EntireRow.Hidden = True

but get the error message "Unable to set the hidden property of the Range class".
If I select the cell then I can get it to work, but this then looks ugly when the macro runs.
How can I hide a column without having to select it?

Posted by Ben O. on July 09, 2001 12:02 PM


Is row1 the name of a variable, or do you just mean the the first row? If you just mean the first row, just change it to Cells(1, curCol).EntireRow.Hidden = True.

If it is the name of a variable, the macro should work if you assigned an integer to it (and to curCol). It works for me, unless there are some cells in the row or column that are protected. If they're protected, you will get that error message.