vba change event with cases copying a range and inserting at a named row stipulates rows used which may change

jtatt

New Member
Joined
May 1, 2019
Messages
32
Hello
I am trying to write a change event which when the value in H6 is >0 the named range "GreenTemplate"(which is three rows deep) is copied and inserted below named range "insertRow" and then the inserted rows are named "GreenQ1".
Then if the value in H6 is cleared the named range is deleted as are the inserted rows.

This only works if no rows are inserted above "insertRow" prior to event

Rows are likely to be inserted above "insertRow" before the event is triggered then the event does not work for inserting or deleting

Is there some clever member who can see a way to resolve this please
Thank you




Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$H$6" Then
Select Case Target.Value
Case Is > 0
Application.Goto Reference:="GreenTemplate"
Selection.Copy
Application.Goto Reference:="insertRow"
Selection.Insert Shift:=xlDown
Application.CutCopyMode = False
ActiveWorkbook.Names.Add Name:="GreenQ1", RefersToR1C1:="=report!R7:R9"
ActiveWorkbook.Names("GreenQ1").Comment = ""
Sheets("control").Select
Range("B3").Select
Case Is = ""
Application.Goto Reference:="GreenQ1"
Selection.Delete Shift:=xlUp
ActiveWorkbook.Names("GreenQ1").Delete
Sheets("control").Select
Range("B3").Select
End Select
End If
End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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