Inserting & deleting a row

  • Thread starter Thread starter Chance
  • Start date Start date
C

Chance

Can someone help me write a macro that would insert a row
of cells above the selected ones on the worksheet? Also
one that would delete a selected row of cells.

Thanks,
Chance
 
Try this Change

For the activecell

Sub test()
ActiveCell.EntireRow.Insert
End Sub

Sub test2()
ActiveCell.EntireRow.Delete
End Sub


For the selcetion

Sub test()
Selection.EntireRow.Insert
End Sub

Sub test2()
Selection.EntireRow.Delete
End Sub
 
Assumes the activecell is top of selected range, will insert a row above that
activecell row.

If selecting from bottom up...

Sub insert_above_selection()
Set rng = Selection
Set rng1 = rng.Offset(0, rng.Columns.Count).Resize(1, 1)
rng1.Activate
rng1.EntireRow.Insert
End Sub

Gord Dibben Excel MVP
 
Or this one

Selection.Cells(1).EntireRow.Insert
Selection.Cells(1).Select
 
Much easier. Why do I always find a hard way?

Maybe because I already had the code to copy and paste?

Gord
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top