Worksheet Change

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

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
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
You should start your procedure with:

Application.EnableEvents = False

and end it with:

Application.EnableEvents = True

Each time you "CHANGE" something inside the worksheet "CHANGE" event you cause the event/procedure to call itself recursively.

Gary
 
Upvote 0
Thanks guys, its not really working as I need the cell to update when the sheet is activated too.
 
Upvote 0
Thanks guys, its not really working as I need the cell to update when the sheet is activated too.

That would be a Worksheet_Activate event. Suggest you create 2 events - Worksheet_Activate and Worksheet_Change, both of which call the same procedure, held in a different module.
 
Upvote 0

Forum statistics

Threads
1,224,551
Messages
6,179,476
Members
452,915
Latest member
hannnahheileen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top