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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,377
Members
448,955
Latest member
BatCoder

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