I would like to add to the VBA code below an exit condition. Which is, in column I, if…
- User
I would like to add to the VBA code below an exit condition. Which is, in column I, if the date value in the cell above the firstEmptyCell is less than Todays date + 30 then pop up a message "Completed Tasks are recent, wait another 30days before commiting to History" then exit sub.
Dim firstEmptyCell As Range Set firstEmptyCell = sourceWS.Range("I:I").Find("", LookIn:=xlValues, LookAt:=xlWhole)
- Assistant
You can add an exit condition to your VBA code using an If statement. Here's an example of how you can modify your code:
Dim firstEmptyCell As Range Set firstEmptyCell = sourceWS.Range("I:I").Find("", LookIn:=xlValues, LookAt:=xlWhole) Dim dateCell As Range Set dateCell = firstEmptyCell.Offset(-1, 0) If dateCell.Value < Date + 30 Then MsgBox "Completed Tasks are recent, wait another 30 days before committing to History" Exit Sub End IfIn the above code, the
dateCellvariable is set to the cell just abovefirstEmptyCell(-1 row offset). Then, an If statement checks if the value indateCellis less than the current date + 30. If this condition is true, a message box will pop up with the specified message, and the code will exit using theExit Substatement.