SpanishSoul89
New Member
- Joined
- Aug 7, 2015
- Messages
- 6
Good morning all,
I'm trying to create a calendar on excel. I'm not proficient in VBA at all but I was able to find a youtube video that matched what I wanted to do. I copied the code but now I'm getting this error:
Compile Error: Else without If
on this part of the code:
This is the whole code I found on youtube:
It's from a channel called ExcelVbalsFun.
Thank you in advance for any help!
I'm trying to create a calendar on excel. I'm not proficient in VBA at all but I was able to find a youtube video that matched what I wanted to do. I copied the code but now I'm getting this error:
Compile Error: Else without If
on this part of the code:
Code:
'determine what weekday 1st is. . .
If Weekday(fMon) = 1 Then stCol = 2
ElseIf Weekday(fMon) = 2 Then stCol = 4
ElseIf Weekday(fMon) = 3 Then stCol = 6
ElseIf Weekday(fMon) = 4 Then stCol = 8
ElseIf Weekday(fMon) = 5 Then stCol = 10
ElseIf Weekday(fMon) = 6 Then stCol = 12
ElseIf Weekday(fMon) = 7 Then stCol = 14
End If
This is the whole code I found on youtube:
Code:
Sub CreateCalendar()
Dim csheet As Worksheet
Set csheet = ThisWorkbook.Sheets("Jan")
selDate = [b3]
fMon = DateSerial(Year(selDate), Month(selDate), 1)
lMon = CDate(Application.WorksheetFunction.EoMo*nth(fMon, 0))
stRow = 6
'clear last cal
Rows(6).ClearContents
Rows(11).ClearContents
Rows(16).ClearContents
Rows(21).ClearContents
Rows(26).ClearContents
Rows(31).ClearContents
'determine what weekday 1st is. . .
If Weekday(fMon) = 1 Then stCol = 2
ElseIf Weekday(fMon) = 2 Then stCol = 4
ElseIf Weekday(fMon) = 3 Then stCol = 6
ElseIf Weekday(fMon) = 4 Then stCol = 8
ElseIf Weekday(fMon) = 5 Then stCol = 10
ElseIf Weekday(fMon) = 6 Then stCol = 12
ElseIf Weekday(fMon) = 7 Then stCol = 14
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
It's from a channel called ExcelVbalsFun.
Thank you in advance for any help!