View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ed Ferrero Ed Ferrero is offline
external usenet poster
 
Posts: 115
Default HowTo insert a blank row and move existing down

Hi Eggle,

Some one-liners for you,

' this inserts a blank row below the currently selected cell
ActiveCell.EntireRow.Insert Shift:=xlDown

' this inserts a blank row below row 2
Rows("2:2").Insert Shift:=xlDown

' this moves a range in sheet 'Passenger' one row down
Dim sht As Worksheet
Dim rng As Range
Dim dest As Range

Set sht = ThisWorkbook.Worksheets("Passenger")
Set rng = sht.Range("A2:E3")
Set dest = rng.Offset(1, 0)

rng.Cut
sht.Paste Destination:=dest

Ok, the last example is longer than one line.

BTW something you get in Excel that you don't see in VS is the macro
recorder. Look in Tools -- Macro. Makes it easy to work out this kind of
stuff.

Ed Ferrero
Microsoft Excel MVP
http://www.edferrero.com

I have

Date C1 C2 C3 C4
10/3 256 212 456 18
10/2 12 98 77 45

I want

Date C1 C2 C3 C4
blank row here - I'll put my new data on this row
10/3 256 212 456 18
10/2 12 98 77 45

p.s. I'm a VS 2003 C# guy not VB, for example

using Excel;

Excel.Worksheet sheet = (Excel.Worksheet)book.Worksheets["Passenger"];
sheet.get_Range("A13", "L99").Clear();
sheet.get_Range("L2", "L4").ClearContents();
Excel.Range rngNow = sheet.get_Range("J9", Missing.Value);