Insert row

G

gav meredith

Hi,

Based upon some type of selection method (check box, value >1, etc) how
would i get excel to insert 2 rows?? ie: cell A1 on sheet1 > 1, then insert
2 rows on sheet2 after a30.....any suggestions would be great!!!!
 
R

Rob van Gelder

Sub test()
If Worksheets("Sheet1").Range("A1").Value > 1 Then
Worksheets("Sheet2").Range("31:32").Insert xlShiftDown
End If
End Sub
 
R

Rob van Gelder

Your request was an example for:

"cell A1 on sheet1 > 1, then insert 2 rows on sheet2 after a30"

That's what the code I supplied does.
 
G

gav meredith

i understand but i am a novice to VB. Do i simply need to insert this or
create a click event??
 
R

Rob van Gelder

Code is triggered to run. How that's triggered depends on what you need it
for.

For example, if you wanted that code to run whenever a button is clicked:
From Visual Basic: Insert Module - insert the code into the module
From Excel: Ensure the Form toolbar is visible (View | Toolbars | Forms)
Drop a Button onto your worksheet (an 'assign macro' window appears)
Assign the macro
 
Top