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

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

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
14,122
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. 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
14,122
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile

ADVERTISEMENT

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,133,649
Messages
5,660,113
Members
418,550
Latest member
kp_

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
Top