VBA code insert, copy and paste with formula and formats for the Number of rows given as input.

evernaren

New Member
Joined
Mar 7, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
: hi all,

please help me in the below vba code, as beginner

in the work sheet, just want to insert the multiple rows through input box and insert after which row through input box.

then i make which row to be copied through input box.

i cannot paste the copied row to the number of rows inserted.

For example, if im inserting 10 rows, after row number 12.
and copying the row number 9 of selected range as (A9:M9), and paste with formula & Formats to newly inserted rows. (This pasting part code im not getting correct)

Private Sub CommandButton1_Click()
Dim iRow As Long
Dim iCount As Long
Dim cRow As Long
Dim i As Long

iCount = InputBox(Prompt:="How many rows you want to add?")
iRow = InputBox _
(Prompt:="After which row you want to add new rows? (Enter the row number")

For i = 1 To iCount
Rows(iRow).EntireRow.Insert
Next i
cRow = InputBox(Prompt:="Which row you need to copy? (Enter the row number)")

Rows("AcRow:LcRow").Select
Selection.Copy
Application.CutCopyMode = False

'Paste formulas and conditional formatting in new row created
Rows(iRow + iCount).PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone

End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,223,702
Messages
6,173,959
Members
452,539
Latest member
delvey

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