Dates in a macro

  • Thread starter Thread starter Ed Davis
  • Start date Start date
E

Ed Davis

I have the code below as well as other code in several macros. What I would
like to do is ref. a cell for the date rather than have to change the macro
every month.
I have check the web and all I can find is information like the code here.
There must be a way.
I want to ref. cell sheet "01" B1 and sheet "Totals" B1.
The cells have the date format as dd-mm-yy.



StartDate = DateSerial(2009, 9, 1)
EndDate = DateSerial(2009, 9, 30)
 
You don't need to reference a cell... VB can read the date from your system
as needed using the built in Date function. These two statements will give
you the start and end date for the current month...

StartDate = Date - Day(Date) + 1
EndDate = DateSerial(Year(StartDate), Month(StartDate) + 1, 0)
 
However I want to use another date it may be in the future or the past.
There are other areas that I use the same type of code and the macro may be
run in the middle of the month.


--
Thank You in Advance
Ed Davis
Rick Rothstein said:
You don't need to reference a cell... VB can read the date from your
system as needed using the built in Date function. These two statements
will give you the start and end date for the current month...

StartDate = Date - Day(Date) + 1
EndDate = DateSerial(Year(StartDate), Month(StartDate) + 1, 0)
 
Maybe...

startdate = worksheets("01").range("B1").value
enddate = worksheets("totals").range("B1").value
 
Back
Top