VBA to Hide Rows

Cagey93

New Member
Joined
Apr 17, 2019
Messages
34
Hello, I am wanting a macro to automatically run when a spreadsheet is opened to check a cell to see what month it is then hide some rows off the back of that.

It should look something like the below saying if C5 is one of those months then hide rows 12-18 in the sheet Check List.

Code:
Private Sub MonthTasks()

For a = 12 To 18


Select Case Range("C5").Value


Case "August", _
     "December", _
     "February", _
     "June", _
     "March", _
     "May", _
     "November", _
     "September"


Then


Worksheets("Check List").Rows(a).Hidden = True




End Sub

Any help appreciated.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
How about
Code:
Private Sub Workbook_Open()
    With Worksheets("Check List")
        Select Case .Range("C5").Value
            Case "August", _
                    "December", _
                    "February", _
                    "June", _
                    "March", _
                    "May", _
                    "November", _
                    "September"
                .Rows("12:18").Hidden = True
        End Select
    End With
End Sub
 
Upvote 0
How about
Code:
Private Sub Workbook_Open()
    With Worksheets("Check List")
        Select Case .Range("C5").Value
            Case "August", _
                    "December", _
                    "February", _
                    "June", _
                    "March", _
                    "May", _
                    "November", _
                    "September"
                .Rows("12:18").Hidden = True
        End Select
    End With
End Sub

This doesn't seem to work, I have put in the code but when opening the spreadsheet it doesn't run, if I go in and run it manually it doesn't do anything either.

I don't get any errors to indicate that a problem has occurred either.

the cell C5 definitely shows atm November with the formula =TEXT(EDATE(TODAY(),0)," MMMM") so that is correct.

I cant think why it wouldn't work.
 
Upvote 0
Hi Sorry,

got it working I have changed C5 to lookup a value in another cell 11 in this months case then show November which seems to work.

Thank you.
 
Upvote 0
Glad you got it sorted & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,147
Members
453,021
Latest member
Justyna P

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