Worksheet Change not working...

wpryan

Well-known Member
Joined
May 26, 2009
Messages
534
Office Version
  1. 365
Platform
  1. Windows
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:

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?
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Which module do you have that code in?
 
Upvote 0
Thanks for the response. It's in the Worksheet_Change event in the Data worksheet. Like I said, if I run the code as a stand-alone Macro, the code is working...
 
Upvote 0
If you run this
Code:
Sub chk()
Application.EnableEvents = True
End Sub
and then change any cell on the "Data" sheet, does your code trigger?
 
Last edited:
Upvote 0
Duh to me! That was it, I disabled events in another place and completely forgot! Thanks a lot!
 
Upvote 0
You're welcome & thanks for the feedback.

We've all been there at some point.
 
Upvote 0

Forum statistics

Threads
1,214,999
Messages
6,122,645
Members
449,093
Latest member
Ahmad123098

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