![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Mar 2002
Posts: 2
|
I am still trying to compute the number of
days between 2 dates. I am able to do so on a NEW worksheet, but for the life of me, I can not do so on an EXISTING worksheet. I am trying to compute the number of days between the current date minus 1/1/1995. Don't know why I can do it on a NEW work sheet, but not on an EXISTING worksheet. I have tried some of the responses to my original posting to no avail. Thanks Al N. |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
What are you getting as an answer on an existing worksheet?
|
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
|
Private Sub Worksheet_Activate()
'Right click on the sheet tab at the bottom 'and select 'View Code' At the top left 'make sure the dropdown 'says 'Worksheet' 'If not then click on the down arrow and 'select 'Worksheet' 'Copy and paste this exactly as it is shown 'here. 'Replace A1 shown below with the cell 'which you wish to display 'the number of days displaced between now 'and 1/1/1995 'Every time you open this worksheet the 'number will be 'refreshed. There are several other options 'but I prefer 'to use VB code instead of formulas Dim ShowDaysInThisCell As String ShowDaysInThisCell = "A1" '<< Replace A1 'if necc. but leave the quotes ActiveSheet.Range(ShowInThisCell).Value = _ DateDiff("d", #1/1/1995#, Now) End Sub |
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
|
Private Sub Worksheet_Activate()
'Right click on the sheet tab at the bottom 'and select 'View Code' At the top left 'make sure the dropdown 'says 'Worksheet' 'If not then click on the down arrow and 'select 'Worksheet' 'Copy and paste this exactly as it is shown 'here. 'Replace A1 shown below with the cell 'which you wish to display 'the number of days displaced between now 'and 1/1/1995 'Every time you open this worksheet the 'number will be 'refreshed. There are several other options 'but I prefer 'to use VB code instead of formulas Dim ShowDaysInThisCell As String ShowDaysInThisCell = "A1" '<< Replace A1 'if necc. but leave the quotes ActiveSheet.Range(ShowInThisCell).Value = _ DateDiff("d", #1/1/1995#, Now) End Sub |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|