john316swan
Board Regular
- Joined
- Oct 13, 2016
- Messages
- 66
- Office Version
- 2019
- Platform
- Windows
I have a worksheet change macro that both updates an offset cell value with a date & a selection of cells with corresponding offset dates, however I am trying to update it so that it only inputs date if the offset cell is blank. Here is the code that works:
Here is the code that doesn't work (run time error '13' type mismatch):
Private Sub Worksheet_Change(ByVal Target As Range)
Thanks in advance for your help, hopefully this is low hanging fruit.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 23 And Target.Cells.Count > 1 Then
Application.EnableEvents = False
For Each cell In Selection
If cell.Value = "done" Then
Target.Offset(0, 1) = Date 'However it just overwrites any previous date that was entered
End If
Next cell
Application.EnableEvents = True
Exit Sub
End If
'This portion of the code works perfectly, I just can't get the selection to work properly
If Target.Column = 23 Then
If Target.Value = "done" And Target.Offset(x, 1) < 1 Then
Application.EnableEvents = False
Target.Offset(x, 1) = Date
Application.EnableEvents = True
End If
End If
End Sub
Here is the code that doesn't work (run time error '13' type mismatch):
Private Sub Worksheet_Change(ByVal Target As Range)
Code:
If Target.Column = 23 And Target.Cells.Count > 1 Then
Application.EnableEvents = False
For Each cell In Selection
If cell.Value = "done" Then
If Target.Offset(0, 1) < 1 Then 'This is line of error
Target.Offset(0, 1) = Date
End If
End If
Next cell
Application.EnableEvents = True
Exit Sub
End If
'This portion of the code works perfectly, I just can't get the selection to work properly
If Target.Column = 23 Then
If Target.Value = "done" And Target.Offset(x, 1) < 1 Then
Application.EnableEvents = False
Target.Offset(x, 1) = Date
Application.EnableEvents = True
End If
End If
End Sub
Thanks in advance for your help, hopefully this is low hanging fruit.