Date Serial Looping VBA

ypompoms

New Member
Joined
Feb 28, 2020
Messages
16
Office Version
  1. 2016
Platform
  1. Windows
Hi,
I need help on the next possible loop. I was able to make a syntax which will show all the calendar days of a specific month and year. However, I also need the succeeding months day after that result within the specified year. How can I do that?
My current syntax is below with result attached. What I wanted to happen next are the succeeding calendar days per column.
Thanks a lot for your help ?

Sub test()

Dim xdate As Date
Dim x As Integer
x = 2
xdate = DateSerial(Range("b2").Value, Range("a2").Value, 1)

Range("C2:C32").Select
Selection.ClearContents

Do While Range("a2").Value = Month(xdate)
Cells(x, 3).Value = xdate
xdate = xdate + 1
x = x + 1

Do

Do While Range("a2").Value = Month(xdate)
Cells(x, y).Value = xdate
xdate = xdate + 1
x = x + 1


Loop


End Sub
 

Attachments

  • Capture.PNG
    Capture.PNG
    22.7 KB · Views: 7

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Hi & welcome to MrExcel.
How about
VBA Code:
Sub test()

Dim xdate As Date
Dim x As Long, y As Long
x = 2
xdate = DateSerial(Range("b2").Value, Range("a2").Value, 1)

Range("C2:C32").ClearContents

Do While Range("a2").Value = Month(xdate)
   Cells(x, 3).Value = xdate
   xdate = xdate + 1
   x = x + 1

Loop
x = 2
y = y + 1
Do While Range("a2").Value = Month(xdate) - y
   Cells(x, y + 3).Value = xdate
   xdate = xdate + 1
   x = x + 1
Loop


End Sub
 
Upvote 0
Or without the loops
VBA Code:
Sub ypompoms()

   Dim xdate As Date
   Dim Dys As Long

   xdate = DateSerial(Range("b2").Value, Range("a2").Value, 1)
   Range("C2:D32").ClearContents
   
   Dys = Day(Application.EoMonth(xdate, 0))
   Range("C2") = xdate
   Range("C2").AutoFill Range("C2").Resize(Dys), xlFillDays
   Range("D2") = xdate + Dys
   Dys = Day(Application.EoMonth(xdate + Dys, 0))
   Range("D2").AutoFill Range("D2").Resize(Dys), xlFillDays
End Sub
 
Upvote 0
Thanks a lot! It actually helped. However, it only gave me the next month. However, I believe it will only give me the next month's days. I need to show the all succeeding months after the indicated month, within the specified year.

thank you so much.
 
Upvote 0
Ok, how about
VBA Code:
Sub ypompoms()

   Dim xdate As Date
   Dim Dys As Long

   xdate = DateSerial(Range("b2").Value, Range("a2").Value, 1)
   Range("C2:N32").ClearContents
   For i = 1 To 12 - Range("A2").Value + 1
      Dys = Day(Application.EoMonth(xdate, 0))
      Cells(2, i + 2) = xdate
      Cells(2, i + 2).AutoFill Cells(2, i + 2).Resize(Dys), xlFillDays
      xdate = xdate + Dys
   Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,046
Messages
6,122,849
Members
449,096
Latest member
Erald

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