Excelnoub
Member
I have the code to restric the dates if they fall on a weekend in a Userform but what about on an activecell?
I have the following code in my Private Sub Worksheet_Change(ByVal Target As Range)
I need that if I add a date in the ActiveCell.Row I, to look in my ActiveCell, "K" and let me know if the date inserted falls on a Weekend, If yes then to have a Msgbox. But if not to continue the code as it should (Exiting sub I presume).
The problem is a do not know how to get this code to work... and where to add this. Should this go after the fact or in the code above?
I have searched all over the net but I need it for my if Cells(ActiveCell.row, "K") falls on Weekend.
Something like this:
I have the following code in my Private Sub Worksheet_Change(ByVal Target As Range)
Code:
If Not Intersect(Target, Range("I5:I20")) Is Nothing Then
Application.EnableEvents = False
For Each rcell In Intersect(Target, Range("I5:I20")).Cells
If Len(rcell.Value) > 0 Then
Cells(ActiveCell.row, "K").FormulaR1C1 = "=IF(RC9="""","""",RC9+40)"
Cells(ActiveCell.row, "J").Value = Cells(ActiveCell.row, "K").Value
Cells(ActiveCell.row, "K").Value = Cells(ActiveCell.row, "J").Value
Else
'If nothing is in the active cell I, then it will remove anything that is in the Active Row, Column K and J
Cells(Target.row, "K").ClearContents
Cells(Target.row, "J").ClearContents
End If
Next rcell
Application.EnableEvents = True
End If
I need that if I add a date in the ActiveCell.Row I, to look in my ActiveCell, "K" and let me know if the date inserted falls on a Weekend, If yes then to have a Msgbox. But if not to continue the code as it should (Exiting sub I presume).
The problem is a do not know how to get this code to work... and where to add this. Should this go after the fact or in the code above?
I have searched all over the net but I need it for my if Cells(ActiveCell.row, "K") falls on Weekend.
Something like this:
Code:
If Weekday() = vbSaturday Or Weekday() = vbSunday Then
MsgBox "Date cannot fall on a weekend, please try again"
End If