VBA Array - Help with Date Calculation

skd1729

New Member
Joined
May 26, 2012
Messages
1
Hi All,

I am a newbie to VBA programming and I am very much interested to correct my mistakes
However, I am unable to solve a problem that involves calculation of Weekdays and storing them in an array

Excel Version: 2007

Problem :
Column A Column B Column C
16-May-13
19-May-13

In the above example , user inputs two dates which can e defined as Start Dates and End Dates(Lets Say 16th May,2013 is the Start Date and 19st May is end Date). Now what i need is that I should be able to create an array that would store details of all the days and dates for all the days between the above dates.

Note: I need this job to be done through Macro instead of to be done via Excel Formulae

Sample Output:
16 May-1316-May-13Thursday
19 May-1317-may-13Friday
18-May-13Saturday
19-May-13Sunday

<tbody>
</tbody>




Sub Dates()
Dim DateArray() As Variant
Dim SDate As Date
Dim EDate As Date
Dim D As Integer
Dim IsDate As Date


SDate = InputBox("Please Input the StartDate")
Sheet1.Range(A1).Value = SDate
EDate = InputBox("Please Enter the EndDate")
Sheet1.Range(A2).Value = EDate


D = (EDate - SDate) + 1
ReDim DateArray(1 To D, 2)
For i = 1 To D


DateArray(i, 1) = SDate
DateArray(i, 2) = Day(DateArray(i, 1))
SDate = SDate + 1
Next
End Sub


Help Needed on :
1. How do i calculate the day of each of these dates ?
2. How do i print this array to one of the columns ?

Many Thanks !
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Forum statistics

Threads
1,214,826
Messages
6,121,793
Members
449,048
Latest member
greyangel23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top