I am working in a excel macro. In that I need to generate all the dates belong to a particular month. Can anybody say how to achieve that?
UPDATE:
I want to receive it as an array of numbers. I tried to use Date related function which were under namespace “System”. But, it is showing error as “object or method not found”. So, I am using Issan’s idea(see below). But, I am getting error as “Object doesn’t support this property or method”.
EDIT:
The “Object doesn’t support this property or method” error went out after I declared a variable as Date. I think the available objects in VBA are depend on declared variables. Thank you to all of you.
(Assuming you meant VBA since you say you are ‘working in an Excel macro’)
Here’s how you can generate an array of Dates for each day in a particular month (there’s not enough info to suggest what format you want so I am assuming an array of dates).
How it works:
You can get the number of days in a month using the dateserial math above. This will ensure that you get the proper amount of days, even considering leap years. Then you just redim your array of days and populate the array!