Hi ,
There is a module which has been used to declare a public variable :
Global PrevValue As String
This used to store the earlier value of the cell in column G , so that if it is changed when it is invalid to change it , the previous value will be restored.
When the workbook is opened , the Workbook_Open event procedure runs , and does the following :
1. Activates the RawData tab
2. Stores the value in cell G2 in the PrevValue variable.
If you intend to implement this feature in some other tab , you will need to change the tab name used in this procedure from RawData to what ever is the tab name where you want this feature to be implemented.
There are 2 more event procedures in the sheet section ; these are :
1. Worksheet_SelectionChange
2. Worksheet_Change
Both of them implement almost the same logic ; the first one comes into effect when you move the cursor into the column which is being validated for the date.
Here it is column G ; if you intend to use a different column , you will have to make the change in both the above 2 procedures , replacing all references to column G by references to the column where you wish to implement this feature.
The code makes use of a helper column , which in the code is column AE ; since this is 24 columns away from column G , you will find that an offset of 24 columns has been used in the code. If you decide to use a column other than column G , you can leave this offset unchanged at 24 , which means that instead of column AE , which ever column is 24 columns away from your used column will be used as the helper column.
The reason for this helper column is to store the date when a new entry is made in column G ; as long as there is no data in the cell in column G , the corresponding cell in column AE will be blank. Now , when a date is entered in the cell in column G , say G13 , the code immediately enters the current date in AE13.
Thereafter , when ever you try to change G13 , the code checks whether the date in AE13 is older than 7 days from today's date ; if it is , it will not permit the change , and even if the change is made will restore the earlier value.
As long as AE13 is not older than 7 days from today's date , you can make changes to G13. When ever a change is made to G13 , the date entered in AE13 is not changed.
If you do wish to change G13 , all you have to do is clear AE13.
Narayan