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
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
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?
 
Upvote 0
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:
Upvote 0
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
 
Upvote 0
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?
 
Upvote 0
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
 
Upvote 0
Neon, you are not an idiot. But, yes I was replying to you initially. And "he's" a "she."

Thanks though!
Cathy
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top