How can I make a simple calendar using VBA (image is given below for reference) ?

Status
Not open for further replies.

abhi221996

New Member
Joined
Sep 29, 2021
Messages
35
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I want to make a simple calendar like this using VBA and also I want exclude weekends from the calendar .Any suggestions?
キャプチャ.PNG
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Try this

VBA Code:
Sub Inputdate()

Dim X As Integer

For X = 1 To 365
     
    Cells(X, 1) = X & "/1/2021"
    Next X
    Cells(1, 1).Select
    Selection.AutoFill Destination:=Range("A1:A365")
    Application.CutCopyMode = False
    Range("B1").FormulaR1C1 = "=RC[-1]"
    Range("B1").Select
    Selection.AutoFill Destination:=Range("B1:B365")
    Range("B1:B365").Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues
    Columns("B:B").Select
    Selection.NumberFormat = "dddd"
    With Selection
        .HorizontalAlignment = xlLeft
        Application.CutCopyMode = False
        Range("A1").Select
    End With
    
End Sub
 
Upvote 0
Thank you. It worked but can't it be done by for loop.
VBA Code:
Sub test()
Dim datr()
startrow = 3
endrow = 30
startdate = Date
ReDim datr(1 To endrow - startrow + 1, 1 To 2)
For i = 1 To (endrow - startrow) + 1 ' start row and end row

    datr(i, 1) = StartDate - 1 + i
    
    
Next i

End Sub

I tried this but I don't know for how to display days and exclude weekends
Try this

VBA Code:
Sub Inputdate()

Dim X As Integer

For X = 1 To 365
    
    Cells(X, 1) = X & "/1/2021"
    Next X
    Cells(1, 1).Select
    Selection.AutoFill Destination:=Range("A1:A365")
    Application.CutCopyMode = False
    Range("B1").FormulaR1C1 = "=RC[-1]"
    Range("B1").Select
    Selection.AutoFill Destination:=Range("B1:B365")
    Range("B1:B365").Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues
    Columns("B:B").Select
    Selection.NumberFormat = "dddd"
    With Selection
        .HorizontalAlignment = xlLeft
        Application.CutCopyMode = False
        Range("A1").Select
    End With
   
End Sub
 
Upvote 0
Hi Abhi,

Check below:

VBA Code:
Sub test()
Dim datr() As Long, startrow As Integer, endrow As Integer
Dim startDate As Date, i As Integer, rowno As Integer
startrow = 3
endrow = 30
startDate = Date
ReDim datr(1 To endrow - startrow + 1, 1 To 2)
rowno = 1
For i = 1 To (endrow - startrow) + 1 ' start row and end row
    datr(i, 1) = startDate - 1 + i
    If CInt(Weekday(datr(i, 1), vbMonday)) <= 5 Then
        Sheets("Sheet3").Range("A" & rowno) = Format(datr(i, 1), "MM/DD/YYYY")
        Sheets("Sheet3").Range("B" & rowno) = WeekdayName(Weekday(datr(i, 1), vbMonday))
        rowno = rowno + 1
    End If
Next i
 
Upvote 0
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,215,006
Messages
6,122,666
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top