ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Count dates (https://www.excelbanter.com/excel-worksheet-functions/141873-count-dates.html)

poolgirl

Count dates
 
I need to keep track of how many dates the local swimming pool is open. When
I type in a date (for instance, May 15) in cell A1, I want cell B1 to tell me
that is day 1. When I enter the next date (May 16) in A1, I want B1 to tell
me it is day 2.
How can I keep track of how many days the pool is open?

AKphidelt

Count dates
 
In A1 enter the beginning date you want to count from
In B1 enter =TODAY()
In C1 enter =B1-A1

Make sure the number format is set to general in cell C1

"poolgirl" wrote:

I need to keep track of how many dates the local swimming pool is open. When
I type in a date (for instance, May 15) in cell A1, I want cell B1 to tell me
that is day 1. When I enter the next date (May 16) in A1, I want B1 to tell
me it is day 2.
How can I keep track of how many days the pool is open?


Gary''s Student

Count dates
 
Looks like you want B1 to be a counter. Each time you change the date in A1,
B1 should increase by one. Use the following Worksheet macro:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Range("A1"), Target) Is Nothing Then
Application.EnableEvents = False
Range("B1").Value = Range("B1").Value + 1
Application.EnableEvents = True
End If
End Sub



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

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

Now try entering material in cell A1. 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




--
Gary''s Student - gsnu200719


"poolgirl" wrote:

I need to keep track of how many dates the local swimming pool is open. When
I type in a date (for instance, May 15) in cell A1, I want cell B1 to tell me
that is day 1. When I enter the next date (May 16) in A1, I want B1 to tell
me it is day 2.
How can I keep track of how many days the pool is open?



All times are GMT +1. The time now is 12:05 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com