I have a problem with properly functioning macro. I wrote a short and simple code to either hide or unhide two last columns, depending on the selected month.
Month selection is possible with a combo box. Each month has assigned a number to it (1 - January, 2 - February, ..., etc.). The number shows in cell A1 and it changes upon selection of a month.
I want my macro to run properly depending on the month number which I choose.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim nr_kol As Long
If Target.Address = "$A$1" Then
For nr_kol = 32 To 34
If Month(Cells(6, nr_kol)) = Cells(1, 1) Then
Columns(nr_kol).Hidden = False
Else
Columns(nr_kol).Hidden = True
End If
Next
End If
End Sub
EDIT(sorry, clicked submit too fast)
Cell A1 changes depending on combobox selection (box is located in a different row). What I have noticed is that columns will hide, but only if cell A1 is changed manually. But when I change the cell to month index containing 30 or 31 days, columns will remain hidden, thus I have two issues.
A1 cell needs to be changed manually (macro is not working whatsoever when change is made by a combobox selection)
When I make a manual change to February - two or three last columns will hide (as these are for the first two/three days of March). However, when I change the number to anything but February (2), columns are still hidden even though at least one should re-appear back again (if month contains 30 days).