I have been given the following code and it works great. I now need to adapt it to the following scenario:
In the attached sheet, the user has to select either, "Suburban" or "Squad" in row 5.
If the user selects, "Suburban" I need this script to compare the values they enter in a given row to the value in column "B".
If the user selects, "Squad" I need this script to compare the values they enter in a given row to the value in column "C".
Look at row 48, for example. If the user enters, "Suburban" in cell D5 then the value they enter in cell D48 should equal "1". If it does not equal "1" then it should proceed with the adding of a comment. Conversely, if the user enters, "Squad" in cell D5 then the value the enter in cell D48 should equal "2". If it does not equal "2" then it should proceed with the adding of a comment.
WHEW! Clear as mud?
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
'I want to exclude columns A and B as well as rows 1, 2, and 3.
If Target.Column < 3 Or Target.Row < 4 Then Exit Sub
Dim MyCmmnt As String
If Sh.Name = "DATA" Then Exit Sub
On Error Goto errorout 'Resume Next
If Target.Value <> Cells(Target.Row, "B").Value Then
MyCmmnt = Application.InputBox("Briefly explain the discrepency", "Comment", Type:=2)
If MyCmmnt = "False" Or Len(Trim$(MyCmmnt)) = 0 Then Exit Sub
With Target
.AddComment
.Comment.Text Text:=Application.UserName & ":" & Chr(10) & MyCmmnt
.Comment.Visible = False
End With
End If
errorout:
Err.Clear
End Sub
Bookmarks