Hello,
I've created a calendar with macros, however when I try to protect the sheet I get a runtime error. I'm learning macros and have tried various codes but have not helped. Here is the macro I have:
Here is the error I when I protect the sheet:
Run -time error '1004':
"Unable to set the Hidden property of the Range class"
Hopefully someone can help!
Thanks in advance!
I've created a calendar with macros, however when I try to protect the sheet I get a runtime error. I'm learning macros and have tried various codes but have not helped. Here is the macro I have:
Code:
Sub HideMonths()
Application.ScreenUpdating = False
Dim rngDates As Range, rngMonths As Range, MyCell As Range
Dim strMonth As String, strYear As String, strMonthYear As String
Set rngDates = [Dates].Cells ' individual dates
Set rngMonths = [Months].Cells ' drop-down list
Set rngYears = [Years].Cells ' drop down list
strMonth = WorksheetFunction.Index(rngMonths, Range("C1"))
strYear = WorksheetFunction.Index(rngYears, Range("C2"))
strMonthYear = Format(DateValue(strMonth & " " & strYear), "mmm yyyy")
For Each MyCell In rngDates
If Format(MyCell, "mmm yyyy") < strMonthYear _
Or Format(MyCell, "mmm yyyy") > strMonthYear Then
Columns(MyCell.Column).Hidden = True
Else
Columns(MyCell.Column).Hidden = False
End If
Next MyCell
Application.ScreenUpdating = True
End Sub
Run -time error '1004':
"Unable to set the Hidden property of the Range class"
Hopefully someone can help!
Thanks in advance!
Last edited by a moderator: