|  

» List and add the days of months in a set period using VBA in Microsoft Excel

Question:
How are the days of a month listed and added into a Worksheet proceeding from a Start- and End date with the current name of the month?


Answer:
Enter the following Code with Excel5/7 in an English-language, with Excel8 in a general Module, assign it to a Button and run it.




Place the code below into the standard module



Sub Days()
Dim sngCounter As Single
Dim intRow As Integer, intDays As Integer
Columns("D:E").ClearContents
sngCounter = Range("B1")
Do
intDays = intDays + 1
If Month(sngCounter) <> Month(sngCounter + 1) Then
intRow = intRow + 1
Cells(intRow, 4) = Format(sngCounter, "mmmm")
Cells(intRow, 5) = intDays
intDays = 0
End If
sngCounter = sngCounter + 1
Loop Until sngCounter > Range("B2")
intRow = intRow + 1
Cells(intRow, 4) = Format(Range("B2"), "mmmm")
Cells(intRow, 5) = Day(Range("B2"))
Cells(intRow + 1, 5) = Application.Sum(Range("E1:E" & intRow))
End Sub


Rate This Tip
12 34 5
Rating: 3.10     Views: 15187
No comments have been submitted.
Click here to post comment
For Registered Users
Name
Comment Title
Comments