VBA: Reference to a workbook / amount of days

  • Thread starter Thread starter Mirja
  • Start date Start date
M

Mirja

Hello!
I need to find out the amount of days in a month with VBA.
The command needs to be linked with a sheet in another
workbook. If the cell within the sheet shows i.e.
February, than monthdays should be 28. So far I have the
following command which is used for the days of the
current month:

days = Day(DateSerial(Year(Date), Month(Date)+1, 0))

How can I change it? Can I refer to another workbook and
sheet for example the following:(workbooks
("abc.xls").Sheets("abc").Range("R20"))?

Thx, Mirja
 
Dim dt as Date
Dim days as Long
dt = Workbooks("abc.xls").Sheets("abc").Range("R20").Value
days = Day(DateSerial(Year(dt), Month(dt)+1, 0))
 

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

Back
Top