naveen_jaina
New Member
- Joined
- Aug 22, 2021
- Messages
- 5
- Office Version
- 365
- Platform
- Windows
Hello
I'm new to learning the VBA macros, and not able to figure out how to resolve one issue here.
I need to create a macro that'd automatically add consecutive dates to different sheets in two weeks of increments (image of the test sheet attached here, not able to get xl2bb to work - sorry). Here's the code that I have wrote so far:
-------------------------------------------
Sub loopdate()
Dim s As Integer
For s = 1 To 9
Sheets(s).Select
Dim d As Date
For d = "09/20/2021" To "10/03/2021"
Dim c As range
For Each c In range("C33")
c.Value = d
ActiveCell.Offset(0, 1).Select
d = d + 1
Next
Next
Next
End Sub
-------------------------------------------
As you can probably see, I need to add two weeks of dates (09/20/2021" To "10/03/2021) in the range ("C33") in Sheet1, and then next two weeks of dates (10/04/2021 to 10/17/2021) in the same range ("C33") in Sheet2 and next two weeks in Sheet3 and so on.
Now, when I run this above code, it works in sheet1, but also adds the first two weeks of dates in Sheet2, Sheet3 and so on. How do I correct it to move to the next two weeks in the second week, please? Hope I am making some sense here.
Thank you so much in advance for all your help.
Nav
I'm new to learning the VBA macros, and not able to figure out how to resolve one issue here.
I need to create a macro that'd automatically add consecutive dates to different sheets in two weeks of increments (image of the test sheet attached here, not able to get xl2bb to work - sorry). Here's the code that I have wrote so far:
-------------------------------------------
Sub loopdate()
Dim s As Integer
For s = 1 To 9
Sheets(s).Select
Dim d As Date
For d = "09/20/2021" To "10/03/2021"
Dim c As range
For Each c In range("C33")
c.Value = d
ActiveCell.Offset(0, 1).Select
d = d + 1
Next
Next
Next
End Sub
-------------------------------------------
As you can probably see, I need to add two weeks of dates (09/20/2021" To "10/03/2021) in the range ("C33") in Sheet1, and then next two weeks of dates (10/04/2021 to 10/17/2021) in the same range ("C33") in Sheet2 and next two weeks in Sheet3 and so on.
Now, when I run this above code, it works in sheet1, but also adds the first two weeks of dates in Sheet2, Sheet3 and so on. How do I correct it to move to the next two weeks in the second week, please? Hope I am making some sense here.
Thank you so much in advance for all your help.
Nav