L
Legacy 464251
Guest
Hello everyone! and thank you for your time.
I work as a financial analyst and I have a VBA question. I would appreciate if you can help me. I'm new to VBA.
So, what I want to do is for excel to hide automatically certain columns depending on the imputs on two cells, which indicate the YEAR and MONTH desired (cells P5 and P6 on the image below). I want the DAY to always be the last possible day of the month.
I have google this, and the best solution I have found is this:
This code works great, but I have two issues. The first one is that it feeds the code with the date in the cell O3 rather than getting the year and month from P5 & P6. To solve this, I have used this formula on the cell O3 =DATE(P5;P6+1;0). The problem I am having now is that when I change either the year or month the colums wont hide until I click on O3 and press enter. I guess the code above requires you to interact with that cell specifically. Changing the value does trigger the code.
The second issue, a minor one, is that I want the month and year imput to be on a different sheet. As this cells are going to be linked to a bunch of sheets.
Can you guys please help me with this? I tried googling it but can't find a solution.
Thank you in advance.
I work as a financial analyst and I have a VBA question. I would appreciate if you can help me. I'm new to VBA.
So, what I want to do is for excel to hide automatically certain columns depending on the imputs on two cells, which indicate the YEAR and MONTH desired (cells P5 and P6 on the image below). I want the DAY to always be the last possible day of the month.
I have google this, and the best solution I have found is this:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim xCell As Range
If Target.Address <> Range("O3").Address Then Exit Sub
Application.ScreenUpdating = False
For Each xCell In Range("B3:M3")
xCell.EntireColumn.Hidden = (xCell.Value < Target.Value)
Next
Application.ScreenUpdating = True
End Sub
This code works great, but I have two issues. The first one is that it feeds the code with the date in the cell O3 rather than getting the year and month from P5 & P6. To solve this, I have used this formula on the cell O3 =DATE(P5;P6+1;0). The problem I am having now is that when I change either the year or month the colums wont hide until I click on O3 and press enter. I guess the code above requires you to interact with that cell specifically. Changing the value does trigger the code.
The second issue, a minor one, is that I want the month and year imput to be on a different sheet. As this cells are going to be linked to a bunch of sheets.
Can you guys please help me with this? I tried googling it but can't find a solution.
Thank you in advance.