Hide columns Macro not working

jbridge

New Member
Joined
Aug 23, 2011
Messages
3
I am encountering the following error in VBA while using Excel 2007/Windows XP:

Run-time error '1004':
Unable to set the hidden property of the range class

Below is the coding which works in months October through January. February(nor will March through September) will not work even though coded the same as other months.

Any ideas to correct very much appreciated??


Private Sub CommandButton3_Click()
'This section unhides every column to start with.
Range("C:es").Select
Selection.EntireColumn.Hidden = False
'The next sections will show months that have actual numbers or the forecast if there are no actuals
'October
If Cells(10, 14).Value = 0 Then
Range("c:l,n:n").Select
Selection.EntireColumn.Hidden = True
Else
Range("c:l").Select
Selection.EntireColumn.Hidden = True
End If
'November
If Cells(10, 14 + 12).Value = 0 Then
Range("o:x,z:z").Select
Selection.EntireColumn.Hidden = True
Else
Range("o:x").Select
Selection.EntireColumn.Hidden = True
End If
'December
If Cells(10, 14 + 24).Value = 0 Then
Range("aa:aj,al:al").Select
Selection.EntireColumn.Hidden = True
Else
Range("aa:aj").Select
Selection.EntireColumn.Hidden = True
End If
'January
If Cells(10, 14 + 36).Value = 0 Then
Range("am:av,ax:ax").Select
Selection.EntireColumn.Hidden = True
Else
Range("am:av").Select
Selection.EntireColumn.Hidden = True
End If
'February
If Cells(10, 14 + 48).Value = 0 Then
Range("ay:bh,bj:bj").Select
Selection.EntireColumn.Hidden = True
Else
Range("ay:bh").Select
Selection.EntireColumn.Hidden = True
End If
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
At what line are you receiving the error message? Click on Debug when you get this message and see which line is highlighted.
 
Upvote 0
The line below is the error(same error for all subsequent months past Feb)

Selection.EntireColumn.Hidden = True
 
Upvote 0
The line below is the error(same error for all subsequent months past Feb)

Selection.EntireColumn.Hidden = True
There's nothing wrong with this line. Try stepping through the code. When you get to the line before this one, verify that the columns you want to hide are selected. If so, then delete the offending line and re-type it from scratch to see if that corrects the problem.
 
Upvote 0
Thanks. That worked for the first month of Feb. I re-typed the code on line before "highlighted" one.

Now it errors out on the next month so trying to re-type not working... very buggy.
 
Upvote 0
Thanks. That worked for the first month of Feb. I re-typed the code on line before "highlighted" one.

Now it errors out on the next month so trying to re-type not working... very buggy.

Your code is OK so stay with the re-typing. Sometimes Excel doesn't see what you've typed the way it appears to you.
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,908
Members
452,949
Latest member
beartooth91

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top