Created
January 25, 2018 13:27
-
-
Save H0neyBadger/c350525a492ec7c899d5e5c3c13f141a to your computer and use it in GitHub Desktop.
Excel activity report
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub ActivityReportMaker() | |
Dim Days(1 To 7) As String | |
Days(1) = "dim" | |
Days(2) = "lun" | |
Days(3) = "mar" | |
Days(4) = "mer" | |
Days(5) = "jeu" | |
Days(6) = "ven" | |
Days(7) = "sam" | |
' Unprotect sheet if had previous calendar to prevent error. | |
ActiveSheet.Protect DrawingObjects:=False, Contents:=False, _ | |
Scenarios:=False | |
' Prevent screen flashing while drawing calendar. | |
Application.ScreenUpdating = False | |
' MyInput. | |
MyInput = InputBox("Type in Month and year for Calendar ") | |
' Allow user to end macro with Cancel in InputBox. | |
If MyInput = "" Then Exit Sub | |
' Get the date value of the beginning of inputted month. | |
StartDay = DateValue(MyInput) | |
' Check if valid date but not the first of the month | |
' -- if so, reset StartDay to first day of month. | |
If Day(StartDay) <> 1 Then | |
StartDay = DateValue(Month(StartDay) & "/1/" & _ | |
Year(StartDay)) | |
End If | |
' Prepare cell for Month and Year as fully spelled out. | |
Range("a1").NumberFormat = "mmmm yyyy" | |
' Put inputted month and year fully spelling out into "a1". | |
Range("a1").Value = Application.Text(MyInput, "mmmm yyyy") | |
' Set variable and get which day of the week the month starts. | |
DayofWeek = Weekday(StartDay) | |
' Set variables to identify the year and month as separate | |
' variables. | |
CurYear = Year(StartDay) | |
CurMonth = Month(StartDay) | |
' Set variable and calculate the first day of the next month. | |
FinalDay = DateSerial(CurYear, CurMonth + 1, 1) | |
' Place a "1" in cell position of the first day of the chosen | |
' month based on DayofWeek. | |
Dim CurDay As Integer | |
For i = 1 To (FinalDay - StartDay) | |
CurDay = Weekday(StartDay + i - 1, 1) | |
Cells(1, i).Value = Days(CurDay) | |
Cells(2, i).Value = i | |
If CurDay > 1 And CurDay < 7 Then | |
Cells(3, i).Value = 1 | |
Cells(4, i).Value = 1 | |
End If | |
Next i | |
End Sub | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment