HowTo insert a blank row and move existing down

G

Guest

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);
 
E

Ed Ferrero

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
 

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

Top