Event Macro

Amy Beryl

Board Regular
Joined
May 5, 2011
Messages
54
Hi All -

I am a new macro writer and my goal is to produce a macro that, at the cursor position, inserts 2 rows and copies a range into it. Then I want the macro to wait until I move to the next insertion point and then do the same thing again. And repeat until I've run out of departments - which is something I will determine. So far I have:

Private Sub Worksheet_Change(ByVal Target As Range)

ActiveCell.Resize(2,1).EntireRow.Insert
Range("A5:I6").Copy Destination:=ActiveCell

End Sub

I'm stumped. Any help (or pity) would be greatly appreciated.

Amy
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
A few questions:
  1. What determines an "insertion point"?
  2. When, exactly, do you want this macro to run?
  3. Will it always be A5:I6 to copy?
 
Upvote 0
I imagine that, after a successful running of the macro, I would scroll down to the next department and do something - enter, edit - anything that would trip the macro to run again. The trigger doesn't really matter. I just want to move to the next place I want to copy the data and metaphorically yell "GO" and have it execute. Then the macro should wait until I find the next department.
 
Upvote 0
Is the copied range always going to be A5:I6 for each time you click? If so then try this:

Note: I put it on BeforeDouble-Click. Could lead to less problems this way.

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
 
Target.Offset(1, 0).Insert Shift:=xlDown
Target.Offset(1, 0).Insert Shift:=xlDown
Range("A5:I6").Copy Destination:=Target.Offset(1, 0)
 
End Sub
 
Upvote 0
Try the following SelectionChange event macro. This will fire whenever you change the cell you are currently on; so be careful what you click! ;)

Code:
Private Sub Worksheet_SelectionChange(ByVal target As Range)
Application.EnableEvents = False
target.Resize(2, 1).EntireRow.Insert
Range("A5:I6").Copy Destination:=target
Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,545
Messages
6,179,432
Members
452,915
Latest member
hannnahheileen

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