Charlie987
New Member
- Joined
- Jul 25, 2020
- Messages
- 25
- Office Version
- 365
- Platform
- Windows
Hi,
Hoping someone might be able to help me adjust this code.
Someone helped me create it so I am not positive how it works (I don't have a lot of experience with VBA)
It aims to print the date twice for each Monday in a user-input month (it prints the date twice for each week).
It works perfectly except where the 31st of the month is the Monday. It is omitting the weeks where Monday is the 31st.
An example is if the user inserts 2021/05/01
it prints:
3/5/21 | 3/5/21 | 10/5/21 | 10/5/21 | 17/05/21 | 17/05/21 | 24/05/21 | 24/05/21
but the 31st should also have been included
Sub SetDates()
Application.ScreenUpdating = False
Dim response As String, d As Date, x As Long, intDay As Integer:
x = 1
intDay = 0
response = InputBox("Enter the date in the format: yyyy/mm/01", "1st of the month")
If Right(response, 2) <> "01" Then
MsgBox ("Enter the darn date correctly")
Exit Sub
End If
d = response
While Format(d + intDay, "mmm") = Format(d + intDay + 1, "mmm")
If Format(d + intDay, "ddd") = "Mon" Then
Cells(1, x).Resize(, 2) = DateSerial(Year(d), Month(d), Format(d + intDay, "d"))
Cells(2, x).Value = "packed"
Cells(2, x + 1).Value = "checked"
x = x + 2
End If
intDay = intDay + 1
Wend
Application.ScreenUpdating = True
End Sub
If any one could point me in the right direction as to how to fix that it would be greatly appreciated.
Thank you very very much.
Hoping someone might be able to help me adjust this code.
Someone helped me create it so I am not positive how it works (I don't have a lot of experience with VBA)
It aims to print the date twice for each Monday in a user-input month (it prints the date twice for each week).
It works perfectly except where the 31st of the month is the Monday. It is omitting the weeks where Monday is the 31st.
An example is if the user inserts 2021/05/01
it prints:
3/5/21 | 3/5/21 | 10/5/21 | 10/5/21 | 17/05/21 | 17/05/21 | 24/05/21 | 24/05/21
but the 31st should also have been included
Sub SetDates()
Application.ScreenUpdating = False
Dim response As String, d As Date, x As Long, intDay As Integer:
x = 1
intDay = 0
response = InputBox("Enter the date in the format: yyyy/mm/01", "1st of the month")
If Right(response, 2) <> "01" Then
MsgBox ("Enter the darn date correctly")
Exit Sub
End If
d = response
While Format(d + intDay, "mmm") = Format(d + intDay + 1, "mmm")
If Format(d + intDay, "ddd") = "Mon" Then
Cells(1, x).Resize(, 2) = DateSerial(Year(d), Month(d), Format(d + intDay, "d"))
Cells(2, x).Value = "packed"
Cells(2, x + 1).Value = "checked"
x = x + 2
End If
intDay = intDay + 1
Wend
Application.ScreenUpdating = True
End Sub
If any one could point me in the right direction as to how to fix that it would be greatly appreciated.
Thank you very very much.
Last edited by a moderator: