Tip Printed from ExcelTip.com
Open data in two dimensional array and save in sheet using VBA in Microsoft Excel


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


Answer:
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