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:
[TABLE="width: 500"]
<tbody>[TR]
[TD]16 May-13[/TD]
[TD]16-May-13[/TD]
[TD]Thursday[/TD]
[/TR]
[TR]
[TD]19 May-13[/TD]
[TD]17-may-13[/TD]
[TD]Friday[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]18-May-13[/TD]
[TD]Saturday[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]19-May-13[/TD]
[TD]Sunday[/TD]
[/TR]
</tbody>[/TABLE]
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 !
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:
[TABLE="width: 500"]
<tbody>[TR]
[TD]16 May-13[/TD]
[TD]16-May-13[/TD]
[TD]Thursday[/TD]
[/TR]
[TR]
[TD]19 May-13[/TD]
[TD]17-may-13[/TD]
[TD]Friday[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]18-May-13[/TD]
[TD]Saturday[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]19-May-13[/TD]
[TD]Sunday[/TD]
[/TR]
</tbody>[/TABLE]
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 !