Hi All,
I have some code that, I expect, should cause some worksheets to be visible or hidden. The code works fine as a Macro, but I want it to be in the worksheet_change event. Somehow it's not firing. The code is like this:
...any ideas?
I have some code that, I expect, should cause some worksheets to be visible or hidden. The code works fine as a Macro, but I want it to be in the worksheet_change event. Somehow it's not firing. The code is like this:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim sht As Worksheet
Dim LastRow As Long
Set sht = Sheets("Data")
LastRow = sht.Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
'Lasik
If Application.WorksheetFunction.CountIf(Range("D19:D" & LastRow), "Lasik") > 0 Then
Sheets("Lasik").Visible = True
Else: Sheets("Lasik").Visible = False
End If
'Rings
If Application.WorksheetFunction.CountIf(Range("D19:D" & LastRow), "ICR") > 0 Then
Sheets("Rings").Visible = True
Else: Sheets("Rings").Visible = False
End If
end sub
...any ideas?