Dates in a macro

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)
 
R

Rick Rothstein

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)
 
E

Ed Davis

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)
 
D

Dave Peterson

Maybe...

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

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

Similar Threads


Top