I have this code which used to pop the systime into a specific cell based on a condition. Formerly I only had two or three cases on this code and it worked perfectly for what I needed. Now I would like to modify the code to pop the word "PENDING" into a specific cell when anything inside a "Range" is changed. I have jurry-rigged it to work similarly to the way I want but its not quite right. The range in this instance is L4:AB4 to L153:AB153. Each row must operate independently and the "hook" for the entry of the word "PENDING" should be if the range contains one or more "x"s. If it matters I could use a countif on the side to find the "x"s which I presume could be easier than doing it in VBA.
Thanks,
tW33k
Thanks,
tW33k
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
' this sub adds a timestamp on the row where data was entered
Dim TargetCell As Range
' check to see if target cell is in the input portion of the worksheet
For Each TargetCell In Target
If (TargetCell.Row >= 3) And (TargetCell.Row <= 154) Then
' check to see if target column is C, D, or G
If (TargetCell.Column = 12) _
Or (TargetCell.Column = 13) _
Or (TargetCell.Column = 14) _
Or (TargetCell.Column = 15) _
Or (TargetCell.Column = 16) _
Or (TargetCell.Column = 17) _
Or (TargetCell.Column = 18) _
Or (TargetCell.Column = 19) _
Or (TargetCell.Column = 20) _
Or (TargetCell.Column = 21) _
Or (TargetCell.Column = 22) _
Or (TargetCell.Column = 23) _
Or (TargetCell.Column = 24) _
Or (TargetCell.Column = 25) _
Or (TargetCell.Column = 26) _
Or (TargetCell.Column = 27) _
Or (TargetCell.Column = 28) Then
Select Case TargetCell.Column
Case 12: intTimeCol = 29 ' set timestamp column to B
Case 13: intTimeCol = 29 ' set timestamp column to B
Case 14: intTimeCol = 29
Case 15: intTimeCol = 29
Case 16: intTimeCol = 29
Case 17: intTimeCol = 29
Case 18: intTimeCol = 29
Case 19: intTimeCol = 29
Case 20: intTimeCol = 29
Case 21: intTimeCol = 29
Case 22: intTimeCol = 29
Case 23: intTimeCol = 29
Case 24: intTimeCol = 29
Case 25: intTimeCol = 29
Case 26: intTimeCol = 29
Case 27: intTimeCol = 29
Case 28: intTimeCol = 29
End Select
If TargetCell.Text <> "" Then ' check to see if the target cell is empty
Cells(TargetCell.Row, intTimeCol).Value = "PENDING" ' add timestamp to target row
Else
Cells(TargetCell.Row, intTimeCol).Value = "" ' delete timestamp if target cell is empty
End If
End If
End If
Next
Dim Result As Integer
Result = Application.WorksheetFunction.CountIf([d_range], "duplicate")
If Result > 0 Then
MsgBox "You have created a duplicate item. Please check the duplicate column.", vbExclamation
End If
End Sub