I need a little VB help

Chamberlain

Board Regular
Joined
Jan 6, 2006
Messages
149
This code is used to insert a row above the active cell, and copy the formula's from an identical row into the new row.'

What I want to be able to do is almost exactly the same thing except, insert the selected number of rows; just like when you insert rows the normal way. So that I could select 1, 5, 25.... or however many rows and have it insert that # of rows, and copy the formulas into each of those new rows.

Dim AR As Long 'Active Row

AR = ActiveCell.Row

Rows(AR).Insert Shift:=xlDown
Range("A8:fq8").Copy Range("A" & AR)
Range("Er8:ft8").Copy Range("ER" & AR + 1)

Thanks,
Dave
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Try:

Code:
Sub Test()
    Dim AR As Long 'Active Row
    Dim r As Variant
    AR = ActiveCell.Row
    r = Application.InputBox(Prompt:="How may rows?", Type:=1)
    If r = False Then Exit Sub
    ActiveCell.Resize(r, 1).EntireRow.Insert
    Range("A8:FT8").Copy Range("A" & AR & ":A" & AR + r - 1)
End Sub
 

onlyadrafter

Well-known Member
Joined
Aug 19, 2003
Messages
5,703
Platform
  1. Windows
Hello,

How about

Dim AR As Long 'Active Row

Code:
AR = ActiveCell.Row
For MY_ROWS = 0 To Selection.Rows.Count - 1
    Rows(AR).Offset(MY_ROWS).Insert Shift:=xlDown
    Range("A8:fq8").Copy Range("A" & AR + MY_ROWS)
    Range("Er8:ft8").Copy Range("ER" & AR + MY_ROWS)
Next MY_ROWS
 

Forum statistics

Threads
1,137,201
Messages
5,680,136
Members
419,885
Latest member
Murugesha

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