Help: Macro won't run after non-trigger cell is modified

BBrandt

Board Regular
Joined
Jul 14, 2008
Messages
155
I have a user-input sheet created with one cell set to control which image is displayed to the right of the table. To accomplish this, I simply stacked all the images and have a macro written to bring the appropriate image to the front.

This works fine if I modify the trigger cell, but as soon as I change another input and then go back and modify the trigger cell again, nothing happens. Can someone please help me figure out why? The code is as follows:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Variables
Dim Old_ScrUpdate As Boolean
Dim KeyCell1 As Range
Set KeyCell1 = [C24]
 
'Prevent screen flicker
Old_ScrUpdate = Application.ScreenUpdating
Application.ScreenUpdating = False
Application.EnableEvents = False
 
'If cells other than C24 are changed, do nothing
If Not Application.Intersect(KeyCell1, Range(Target.Address)) _
    Is Nothing Then
        If [C24] = "0" Then
            Shapes("Case0Iso").ZOrder msoBringToFront
            Shapes("Case0Top").ZOrder msoBringToFront
        End If
 
        If [C24] = "1" Then
            Shapes("Case1Iso").ZOrder msoBringToFront
            Shapes("Case1Top").ZOrder msoBringToFront
        End If
 
        If [C24] = "2" Then
            Shapes("Case2Iso").ZOrder msoBringToFront
            Shapes("Case2Top").ZOrder msoBringToFront
        End If
 
        'Only show user inputs in rows 35/36 if config is type 3
        If [C24] = "3" Then
            'Sheet1.Unprotect
            Rows("35:36").Hidden = False
            Shapes("Case3Iso").ZOrder msoBringToFront
            Shapes("Case3Top").ZOrder msoBringToFront
            'Sheet1.Protect
        Else
            'Sheet1.Unprotect
            Rows("35:36").Hidden = True
            'Sheet1.Protect
    End If
 
Application.ScreenUpdating = Old_ScrUpdate
Application.EnableEvents = True
 
End If
 
End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
You are re-enabling events INSIDE your If structure. Move the screenupdating and enableevents below the last end if. What is happening is when the modified cell is not the trigger cell, you are turning off events but not re-enabling them again.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
 
Upvote 0

Forum statistics

Threads
1,215,339
Messages
6,124,370
Members
449,155
Latest member
ravioli44

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