Formula to help with Date funtion

B

btyler

Hi I'm currently using the following formula :

=IF(E7="","",E7-TODAY())

This works fine and works out for me the number of days between todays date
and another variable date. What I would like is that when cell L7 is
populated the amove formular stops and will forever show the last result.

To explain a little better, If my answer from the above formular is 21 and
today i imput data either text or number into L7, I want the 21 to stay
fixed, so when i open the sheet tomorrow, it will still read 21 and not
increase to 22

Thanks in advance
 
R

royUK

You can't use TODAy & it not change, TODAY() is a volatile function and
will always change to show today's date.
 
G

Gary''s Student

Put the following event macro in the worksheet code area:

Private Sub Worksheet_Change(ByVal Target As Range)
Set t = Target
Set L7 = Range("L7")
If Intersect(t, L7) Is Nothing Then Exit Sub
If L7.Value = "" Then Exit Sub
Set ff = Range("I7")
Application.EnableEvents = False
ff.Value = ff.Value
Application.EnableEvents = True
End Sub


Because it is worksheet code, it is very easy to install and automatic to use:

1. right-click the tab name near the bottom of the Excel window
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window

If you have any concerns, first try it on a trial worksheet.

If you save the workbook, the macro will be saved with it.


To remove the macro:

1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm
 
B

btyler

Many Thanks for that

Gary''s Student said:
Put the following event macro in the worksheet code area:

Private Sub Worksheet_Change(ByVal Target As Range)
Set t = Target
Set L7 = Range("L7")
If Intersect(t, L7) Is Nothing Then Exit Sub
If L7.Value = "" Then Exit Sub
Set ff = Range("I7")
Application.EnableEvents = False
ff.Value = ff.Value
Application.EnableEvents = True
End Sub


Because it is worksheet code, it is very easy to install and automatic to use:

1. right-click the tab name near the bottom of the Excel window
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window

If you have any concerns, first try it on a trial worksheet.

If you save the workbook, the macro will be saved with it.


To remove the macro:

1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top