Excel VBA Tips n Tricks #16 Make a Calendar in Excel VBA
Автор: ExcelVbaIsFun
Загружено: 2013-04-08
Просмотров: 66566
📊 Free Workbooks: https://www.excelvbaisfun.com/links?u...
🥷Join Excel Ninja Pro: https://www.excelvbaisfun.com/ninjapr... Months FREE On Annual Plan Auto Applied)
🥷Excel Ninjas FB Group: https://www.excelvbaisfun.com/xlninjas (Free downloads, Trainings, Live Q&A and more)
Make a CALENDAR from scratch in Excel using VBA. This is dynamic, so when you choose a different month, it will erase the last one and plug in the new one. The great part about it is, learning these concepts will help you master the ability to customize and tweak this lesson's codes to your needs. Thanks and enjoy!
Here's the (fixed) code:
Sub CreateCalendar()
Dim csheet As Worksheet
Set csheet = ThisWorkbook.Sheets("Sheet1")
selDate = [b1]
fMon = DateSerial(Year(selDate), Month(selDate), 1)
lMon = CDate(Application.WorksheetFunction.EoMonth(fMon, 0))
stRow = 4
'clear last cal
Rows(4).ClearContents
Rows(9).ClearContents
Rows(14).ClearContents
Rows(19).ClearContents
Rows(24).ClearContents
Rows(29).ClearContents
'determine what weekday 1st is. . .
If Weekday(fMon) = 1 Then
stCol = 2
ElseIf Weekday(fMon) = 2 Then
stCol = 3
ElseIf Weekday(fMon) = 3 Then
stCol = 4
ElseIf Weekday(fMon) = 4 Then
stCol = 5
ElseIf Weekday(fMon) = 5 Then
stCol = 6
ElseIf Weekday(fMon) = 6 Then
stCol = 7
ElseIf Weekday(fMon) = 7 Then
stCol = 8
End If
For x = 1 To Day(lMon)
If FirstT = Empty Then
csheet.Cells(stRow, stCol) = fMon
FirstT = 1
Else
fMon = fMon + 1
csheet.Cells(stRow, stCol) = fMon
End If
If stCol = 8 Then
stCol = 2
stRow = stRow + 5
Else
stCol = stCol + 1
End If
Next x
End Sub
Fantastic Developer Tools:
🔒 Transform Any Excel File Into A Locked EXE: https://www.excelvbaisfun.com/secure-... (25% off with code ‘25OFF’)
🟡 Create Custom Installers: https://www.excelvbaisfun.com/custom-...
👋 Business Inquiries, Consulting, Comments, etc: https://www.excelvbaisfun.com/contact/
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: