Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

hiding rows with If statement for a calander

So I am a student and my chef gave me the task of making the occupancy plan in excel more dynamic. Now I want to hide the columns if they dont belong to the specific month but it doesnt work like I want it. The days are now only shown up to the 28. of every month.
What is wrong here?

Sub montatslen()

Dim spaltenr As Integer

For spaltenr = 32 To 34
    If Cells(3, 7).Value = Month(Cells(14, spaltenr).Value) Then
        Columns(spaltenr).EntireColumn.Hidden = False
    Else
        Columns(spaltenr).EntireColumn.Hidden = True
    End If
Next spaltenr

End Sub

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I tried writing it this way and it seemed to work. It hides columns AF, AG and AH

Sub montatslen()

Dim spaltenr As Integer

For spaltenr = 32 To 34
    
    columnLetter = Split(Cells(1, spaltenr).Address, "$")(1)
    
    If Range("G3").Value = Month(Range(columnLetter & "14").Value) Then
        Columns(spaltenr).EntireColumn.Hidden = False
    Else
        Columns(spaltenr).EntireColumn.Hidden = True
    End If
Next spaltenr

End Sub
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading