Jammydan
Board Regular
- Joined
- Feb 15, 2010
- Messages
- 141
hi Can anybody help with the below code. It works fine until I add the "For each cell in cash" lines?
Many thanks
Many thanks
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range '** only look at single cell changes
Dim ltv As Range
Dim cash As Range
Set ltv = Range("AC8:AC20")
Set cash = Range("L8:L20")
ActiveSheet.Unprotect
For Each cell In cash
If cell.Value = "Cash" Then
cell.Offset(0, 10) = cell.Offset(0, 6)
ElseIf cell.Value = "Shares" Then
cell.Offset(0, 10) = cell.Offset(0, 9)
End If
Next
For Each cell In ltv
If cell.Value < cell.Offset(0, -2) And cell.Offset(0, -26) = "TOTAL" Then ' Orange
Range("C" + CStr(cell.Row) + ":AC" + CStr(cell.Row)).Interior.ColorIndex = 46
ElseIf cell.Value < cell.Offset(0, -1) And cell.Offset(0, -26) = "TOTAL" Then ' Dark Orange
Range("C" + CStr(cell.Row) + ":AC" + CStr(cell.Row)).Interior.ColorIndex = 45
ElseIf cell.Value > cell.Offset(0, -2) And cell.Offset(0, -26) = "TOTAL" Then ' Green
Range("C" + CStr(cell.Row) + ":AC" + CStr(cell.Row)).Interior.ColorIndex = 43
End If
Next
ActiveSheet.Protect
If Target.count > 1 Then Exit Sub
Set rng = Range("W8:W200")
If Intersect(Target, rng) Is Nothing Then Exit Sub
Target.Offset(0, 1) = Date
If Intersect(Target, rng) = "" Then
Target.Offset(0, 1) = ""
End If
ActiveSheet.Protect
End Sub