Dear experts. I am new to Excel Macro and I would like to create an Excel Macro programming code so that it will unhide/hide one certain page based on a calculated cell value. More specifically, I would like to find a value "B1-A1" (A1 and B1 are dates), with a conditional statement on "C1" (explained below), if "B1-A1<180 (half a year)" then unhide the "Data page", if not then hide the "Data page".
The code I am currently using is :
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Target, Range("C1")) Is Nothing Then
If Range("C1").Value = 1 And Not IsEmpty(Range("C1")) Then
Sheets("Data Form").Visible = xlSheetVisible
Else
Sheets("Data Form").Visible = xlSheetHidden
End If
End If
End Sub
Here I am using a "IF statement" in cell C1, if B1-A1=<180 then C1=1 (unhide page), otherwise C1=0 (hide page). The PROBLEM I am having is the code does not run if the value in C1 is calculated ("1" or "0" based on "A1-B1" condition). But if I enter "1" or "0" from keyboard it works.
Please give me some help to solve this problem.
Many thanks in advance!!
The code I am currently using is :
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Target, Range("C1")) Is Nothing Then
If Range("C1").Value = 1 And Not IsEmpty(Range("C1")) Then
Sheets("Data Form").Visible = xlSheetVisible
Else
Sheets("Data Form").Visible = xlSheetHidden
End If
End If
End Sub
Here I am using a "IF statement" in cell C1, if B1-A1=<180 then C1=1 (unhide page), otherwise C1=0 (hide page). The PROBLEM I am having is the code does not run if the value in C1 is calculated ("1" or "0" based on "A1-B1" condition). But if I enter "1" or "0" from keyboard it works.
Please give me some help to solve this problem.
Many thanks in advance!!