Application.enableevent code within a worksheet change sub

Danielle22103

New Member
Joined
Dec 15, 2005
Messages
13
Hi there

I have a simple code that hides rows when either W or S is selected in a cell ("H19"). I want the code to disable after a selection is made so the application.goto does not activate every time i populate a cell, however code should be activated again when the cell ("H19") contents is changed at any time. I know i should use the enable event in this code however it doesn't reactivate my code when changed more than once.

Private Sub Worksheet_Change(ByVal Target As Range)
If Range("H19").Value = "W" Then
Range("20:150,157:302").Select
Selection.EntireRow.Hidden = True
Range("151:156").Select
Selection.EntireRow.Hidden = False
Application.Goto Range("H153")
ElseIf Range("H19").Value = "S" Then
Range("151:302").Select
Selection.EntireRow.Hidden = True
Range("20:25").Select
Selection.EntireRow.Hidden = False
Application.Goto Range("H22")


End If

End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Try a simple modification:
Code:
[COLOR=#0000ff]Private Sub[/COLOR] Worksheet_Change([COLOR=#0000ff]ByVal[/COLOR] Target [COLOR=#0000ff]As[/COLOR] Range)
[COLOR=#008000]    'If Cell H19 is not selected the sub will be exited[/COLOR]
    [COLOR=#0000ff]If [/COLOR]Target.Address = "$H$19" [COLOR=#0000ff]Then[/COLOR]
    
      [COLOR=#0000ff]  If[/COLOR] Target.Value = "W" [COLOR=#0000ff]Then[/COLOR]
            Range("20:150,157:302").Select
            Selection.EntireRow.Hidden = [COLOR=#0000ff]True[/COLOR]
            Range("151:156").Select
            Selection.EntireRow.Hidden = [COLOR=#0000ff]False[/COLOR]
            Application.Goto Range("H153")
        [COLOR=#0000ff]ElseIf [/COLOR]Target.Value = "S" [COLOR=#0000ff]Then[/COLOR]
            Range("151:302").Select
            Selection.EntireRow.Hidden = [COLOR=#0000ff]True[/COLOR]
            Range("20:25").Select
            Selection.EntireRow.Hidden = [COLOR=#0000ff]False[/COLOR]
            Application.Goto Range("H22")
[COLOR=#0000ff]        End If[/COLOR]
[COLOR=#0000ff]        [/COLOR]
[COLOR=#0000ff]    End If[/COLOR]
[COLOR=#0000ff]    [/COLOR]
[COLOR=#0000ff]End Sub[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,215,427
Messages
6,124,831
Members
449,190
Latest member
rscraig11

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