Macro Help: Add 30 rows after selected row

ACF0303

New Member
Joined
Aug 29, 2013
Messages
41
By way of explanation, I am going crazy breaking down some data that was compiled as totals rather than line by line. So..after
each process type, I need to add 30 blank rows and then add the dates September 1 - 30, 2014 to those rows. And go through a lot of other manual stuff to normalize the data. Anything to make this faster would e welcome. Sine I am repeatedly adding 30 rows, I thought maybe a macro.....turns out my limited knowledge of VBA doesn't go that far.... Any help greatly appreciated!

Cathy
 

Some videos you may like

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

NeonRedSharpie

Well-known Member
Joined
Jul 14, 2014
Messages
1,678
Code:
Sub addRowsAndDate()

    For x = 30 To 1 Step -1
        With Selection
            .Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
            .Value = "9/" & x & "/2014"
        End With
    Next x
End Sub
Something like this?
 

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
12,688
Office Version
365, 2010
Platform
Windows, Mobile
or possibly a non-looping method (you might need to reverse the 1 and 9 in CDate as I am in UK regional settings)

Rich (BB code):
Sub insertit()
    Application.ScreenUpdating = False
    Rows(Selection.Row).Resize(30).Insert Shift:=xlDown
    Cells(Selection.Row, "A").Value = CDate("1/9/14")
    Cells(Selection.Row, "A").AutoFill Destination:=Cells(Selection.Row, 1).Resize(30), Type:=xlFillDefault
    Application.ScreenUpdating = True
End Sub
 
Last edited:

ACF0303

New Member
Joined
Aug 29, 2013
Messages
41
I appreciate the quick response. This isn't working quite as I need it to. I need the macro to add 30 new rows below the selected cell. This is just repopulating 30 existing rows with dates so no joy....

Thanks for the effort though!
Cathy
 

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
12,688
Office Version
365, 2010
Platform
Windows, Mobile
This isn't working quite as I need it to. I need the macro to add 30 new rows below the selected cell.
ACFO303, Which code/post are you replying to?
 

NeonRedSharpie

Well-known Member
Joined
Jul 14, 2014
Messages
1,678
ACFO303, Which code/post are you replying to?

I assume he's replying to mine because I was an idiot. I didn't offset anything so it just wrote over the selected cell. See below edited.

Code:
Sub addRowsAndDate()

    For x = 30 To 1 Step -1
        With Selection
            .Offset(1, 0).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
            .Offset(1, 0).Value = "9/" & x & "/2014"
        End With
    Next x
End Sub
 

ACF0303

New Member
Joined
Aug 29, 2013
Messages
41
Neon, you are not an idiot. But, yes I was replying to you initially. And "he's" a "she."

Thanks though!
Cathy
 

Watch MrExcel Video

Forum statistics

Threads
1,099,503
Messages
5,468,994
Members
406,627
Latest member
IncandenzaH1997

This Week's Hot Topics

Top