How to create VBA dynamic array in Microsoft Excel

The weekdays and dates of a month are to be opened in a two-dimensional array and then inserted in the sheet

Place the code below into the standard module.

 Sub dayarray()
   Dim arrDay(1 To 31, 1 To 2) As Variant
   Dim intCounter As Integer
   For intCounter = 1 To 31
      arrDay(intCounter, 2) = DateSerial(Year(Date), 12, intCounter)
      arrDay(intCounter, 1) = Format(arrDay(intCounter, 2), "dddd")
   Next intCounter
   Range("A1:B31").Value = arrDay
End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *

Terms and Conditions of use

The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.