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
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