I have code that watches three different columns for changes.
It works great when only one cell changes at a time.
But if I copy and paste multiple cells of data in to the columns at a single time, it doesn't work.
I am pretty sure that I know why, but I can't figure out how to change it to watch for multiple cell changes and only take effect for the rows where the cells changed.
Here is my code:
I have made bold where I think the issue is stemming from, but again, I don't know exactly how to go about changing it to capture any and all changes to those specific columns, regardless if it is a single cell or multiple cells.
Any thoughts, ideas, suggestions?
Thanks in advance!
-Spydey
It works great when only one cell changes at a time.
But if I copy and paste multiple cells of data in to the columns at a single time, it doesn't work.
I am pretty sure that I know why, but I can't figure out how to change it to watch for multiple cell changes and only take effect for the rows where the cells changed.
Here is my code:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim wb As Workbook
Dim ws As Worksheet
Set wb = ThisWorkbook
Set ws = wb.Worksheets(1)
[B]If Target.Cells.Count > 1[/B] Then Exit Sub
If [B]Target.Count = 1[/B] And Target.Column = 5 Then
If IsEmpty(Target.Value) Then
Target.Offset(0, 2).ClearContents
Else
If IsDate(Target.Value) And IsEmpty(Target.Offset(0, 1).Value) Then
Target.Offset(0, 2).ClearContents
Else
If IsDate(Target.Value) And IsDate(Target.Offset(0, 1).Value) Then
Target.Offset(0, 2) = Application.WorksheetFunction.Days(Target.Offset(0, 1).Value, Target.Value) + 1
End If
End If
End If
ElseIf [B]Target.Count = 1[/B] And Target.Column = 6 Then
If IsEmpty(Target.Value) Then
Target.Offset(0, 1).ClearContents
Else
If IsDate(Target.Value) And IsEmpty(Target.Offset(0, -1).Value) Then
Target.Offset(0, 1).ClearContents
Else
If IsDate(Target.Value) And IsDate(Target.Offset(0, -1).Value) Then
Target.Offset(0, 1) = Application.WorksheetFunction.Days(Target.Value, Target.Offset(0, -1).Value) + 1
End If
End If
End If
ElseIf [B]Target.Count = 1[/B] And Target.Column = 8 Then
If UCase(Target.Value) = "PASS" Or UCase(Target.Value) = "FAIL" Then
Target.Offset(0, 1) = Date
Else
Target.Offset(0, 1).ClearContents
End If
End If
End Sub
I have made bold where I think the issue is stemming from, but again, I don't know exactly how to go about changing it to capture any and all changes to those specific columns, regardless if it is a single cell or multiple cells.
Any thoughts, ideas, suggestions?
Thanks in advance!
-Spydey