Row insert - vba code breaks

Ikhan99

New Member
Joined
Mar 9, 2016
Messages
3
Hello,

Below code breaks - if any rows are inserted between row 5 and row 20.

kindly assist in modfying below code.



Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    ay = Target.Row
    ax = Target.Column
    If ax = 10 Then
        Application.ScreenUpdating = False
        Application.EnableEvents = False
        With Sheets("Output")
            Select Case ay
                Case 5
                    x = WorksheetFunction.Match(Sheets("Output").Range("$J$5"), Sheets("Dropdown").Range("$G$1:$G$13"), 0) - 2
                    .Range(.Cells(6, 12 + x * 3), .Cells(19, 13 + x * 3)).Copy Destination:=.Range("$J$6")
                Case 6 To 20
                    yy = WorksheetFunction.Sum(.Range("$J$6:$J$19"))
                    .Range("$K$6:$K$19").NumberFormat = "0%"
                    .Range("$j$6:$j$19").NumberFormat = "0"
                    For y = 6 To 19
                      .Cells(y, 11) = .Cells(y, 10) / yy
                    Next y
                    x = WorksheetFunction.Match(Sheets("Output").Range("$J$5"), Sheets("Dropdown").Range("$G$1:$G$13"), 0) - 2
                    .Cells(5, 12 + x * 3) = Sheets("Dropdown").Cells(2 + x, 7)
                    .Cells(5, 13 + x * 3) = .Cells(5, 12 + x * 3) & " Act"
                    .Range("$J$6:$K$19").Copy Destination:=.Cells(6, 12 + x * 3)
                    .Range("J20") = yy
                    .Cells(20, 12 + x * 3) = yy
            End Select
        End With
        Application.EnableEvents = True
        Application.ScreenUpdating = True
    End If
End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

Forum statistics

Threads
1,215,217
Messages
6,123,675
Members
449,116
Latest member
HypnoFant

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