In the VBA code the part of the code below 'If Range("D22").Value = "" Then' works…
- User
In the VBA code the part of the code below 'If Range("D22").Value = "" Then' works exactly as I want it to. Will the parto fothe code that is controlled by 'If daysToEndOfMonth > 7 And daysToEndOfMonth < 14 Then' work as intended, clearContents of D22.
If the date in A2 falls within the first seven days of a month then the chnage the value of D22 to "".
Public Sub CheckNewMonth() Dim currentDate As Date Dim nextMonthDate As Date Dim daysToEndOfMonth As Integer
currentDate = Date nextMonthDate = DateSerial(Year(currentDate), Month(currentDate) + 1, 1) daysToEndOfMonth = nextMonthDate - currentDate If daysToEndOfMonth > 7 And daysToEndOfMonth < 14 Then ActiveSheet.Unprotect Password:="edit" Range("D22").ClearContents End If If Range("D22").Value = "" Then If daysToEndOfMonth <= 7 Then If daysToEndOfMonth <= 3 Then MsgBox "Please Back Up archived Sheets NOW!", vbInformation, "BACKUP SHEETS" ElseIf daysToEndOfMonth > 3 Then MsgBox "You will have to Back Up archived Sheets soon", vbInformation, "BACKUP SHEETS" End If End If End If ActiveSheet.Protect Password:="edit"End Sub
- Assistant
Yes, the part of the code controlled by 'If daysToEndOfMonth > 7 And daysToEndOfMonth < 14 Then' will work as intended. If the date in A2 falls within the first seven days of a month, the value of D22 will be cleared. The subsequent checks for the value of D22 and the days remaining in the month will also be executed as expected.