Copy and paste with input box

Lacampeona

New Member
Joined
Mar 31, 2024
Messages
7
Office Version
  1. 2016
Platform
  1. Windows
Hello Excel experts
I am new here
I have one question if that is possible

I have a range of cells that i want to copy after some cells bellow
A2:D2

1711877817485.png


see the attachement

I would like to create some input box to the user

like bellow
but in my case it copies entire row i want the selection of cells

thank you in advance excel experts


Dim iRow As Long
Dim iCount 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
 

Attachments

  • 1711877747118.png
    1711877747118.png
    27.1 KB · Views: 16
  • 1711877776261.png
    1711877776261.png
    28.4 KB · Views: 18

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Perhaps something like this.
VBA Code:
Sub Copy_and_paste_with_input_box()
    Dim iRow As Long, iCount As Long, iCopy As Long
    Dim Ans As String

    Ans = InputBox(Prompt:="Which row do you want to copy from?")
    If Ans <> "" And IsNumeric(Ans) Then
        iCopy = CLng(Ans)
    Else
        Exit Sub
    End If

    Ans = InputBox(Prompt:="How many copies do you want?")
        If Ans <> "" And IsNumeric(Ans) Then
        iCount = CLng(Ans)
    Else
        Exit Sub
    End If
    
    Ans = InputBox(Prompt:="After which row do you want to paste the data?")
    If Ans <> "" And IsNumeric(Ans) Then
        iRow = CLng(Ans)
    Else
        Exit Sub
    End If

    Cells(iRow, 1).Resize(iCount, 1).EntireRow.Insert
    Cells(iCopy, 1).Resize(1, 4).Copy Cells(iRow, 1).Resize(iCount, 1)
End Sub

Before
Book2
ABCD
1
2NameSurnameYearSport
3Lukadoncic2024Basketball
4
5
6
7
8
9
10
11
Sheet1


After
Book2
ABCD
1
2NameSurnameYearSport
3Lukadoncic2024Basketball
4
5
6
7Lukadoncic2024Basketball
8Lukadoncic2024Basketball
9Lukadoncic2024Basketball
10
11
Sheet1
 
Upvote 0
Solution

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

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