worksheet_change() isn't changing!

ieJasonW

New Member
Joined
Mar 4, 2010
Messages
31
Ok, I have a spreadsheet that allows someone to update cell AF,20 with a number. When they do that, the worksheet_change() function is supposed to format a range of cells based on the input value.

Well, I tested the code by changing the number -- and I got an error. I fixed the problem, but now the worksheet_change() won't change my spreadsheet! I hit STOP. But it won't work. :(

ieJasonW

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim i As Integer, j As Integer, nl As Integer
  Dim ns As Integer
  
If Not ((Target.Address = "$AF$20") Or (Target.Address = "$AG$35")) Then
    Exit Sub
End If

If Target.Address = "$AF$20" Then
    
    Application.ScreenUpdating = False
    Application.EnableEvents = False 'Must turn this off to alter the worksheet
    
    ns = Cells(20, 32).Value 'Number of Stages
    
        'clears the cells gives them plain formatting
        For i = 1 To 12 'upto 12 stages
            For j = 1 To 7 'for each of 6 stage properties and stage number column
                Cells(17 + j, 34 + i).ClearContents
                Cells(17 + j, 34 + i).Borders.ColorIndex = 2
                Cells(17 + j, 34 + i).Interior.ColorIndex = 2
                Cells(17 + j, 34 + i).Font.ColorIndex = xlColorIndexAuto
            Next j 'Next row
        Next i 'Next column
        
        'For ns number of stages, enter in the stage number title in the appropriate column
        For i = 1 To ns
                Cells(18, 34 + i).Value = i
        Next i 'Next layer
        
        'Formats the inner cells of the Injection Stage Properties table
        For i = 1 To ns 'for ns number of stages
            For j = 1 To 6 'for 6 stage properties
                Cells(18 + j, 34 + i).Interior.Color = RGB(255, 255, 204) 'Set interior color to peach
                Cells(18 + j, 34 + i).Select 'select new cell
         
                With Selection
                    .ColumnWidth = 9
                    With .Borders 'give selection a border
                        .LineStyle = xlContinuous
                        .Weight = xlThin
                        .Color = RGB(192, 192, 192) 'set color to light grey
                    End With
                End With
            Next j 'Next row
        Next i 'Next column
        
    Cells(20, 32).Select
    
    Application.ScreenUpdating = True
    Application.EnableEvents = True
    
    End If 'End of Dynamic Formatting
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
In the VBE, do Ctrl+G to see the Immediate window if it's not already visible.

In there, paste

Code:
Application.EnableEvents = True
and hit Enter
 
Upvote 0
Sounds like Events did not get turned back on after your error.

Type and Enter the following line in the Immediate Window of the VBA editor.
Application.EnableEvents = True
(Ctrl-G will open the Immediate window…)
 
Upvote 0

Forum statistics

Threads
1,215,394
Messages
6,124,683
Members
449,180
Latest member
kfhw720

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