Copy and Paste Values to Next Empty Row with Excel VBA (3 Examples)

Method 1 – Copy a Range of Cells and Paste Values from the Next Empty Row in Excel Using VBA Code

In this particular example, we will copy row 11 and paste it to the next blank row.

Steps:

  • Press Alt + F11 to open the VBA code editor.
  • Create a new Module from the Insert tab.

Create a new module to Copy a Range of Cells and Paste Values from the Next Empty Row in Excel Using VBA Code

  • Copy the following VBA code:
Sub PasteToNextEmptyRow()
Range("B11:E11").Copy
Sheets("Sheet1").Range("B" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues

End Sub
  • Paste the code in the VBA editor and save it.

Copy a Range of Cells and Paste Values from the Next Empty Row in Excel Using VBA Code

  • Hit the Run Sub button or press F5 to run the code.

Read More: Excel VBA to Copy Only Values to Destination


Method 2 – Copy the Contents of a Row and Paste Values to the Next Empty Row in Excel VBA with a Condition

  • Open the VBA code editor by pressing Alt + F11.
  • Go to Insert and choose Module.

  • Input the following VBA code into the module:
Sub PasteValuesToNextEmptyRow()

Dim m As Long
m = WorksheetFunction.Max(3, Cells(Rows.Count, "B").End(xlUp).Row)
If m >= 12 Then
MsgBox "Limit Reached."
Exit Sub
End If
Range("B11:E11").Copy
Range("B" & m + 1).PasteSpecial xlPasteValues
End Sub
  • Save the code in the VBA editor.

Copy the Contents of a Row and Paste Values to the Next Empty Row in Excel VBA with Condition

  • Press F5 to run the code.

  • We set up a condition in the code. When you reach the row limit up to row 12, it will show an alert which is Limit Reached. You can change the limit.

Read More: Excel VBA: Copy Row If Cell Value Matches


Method 3 – Copy the Contents of a Row and Paste Values to the Next Empty Row in Another Worksheet Using Excel VBA

  • Press Alt + F11 to open the VBA editor.
  • Click Insert and choose Module.

  • Insert the following VBA code into the module.
Private Sub PasteNextEmptyRowAnotherSheet()

Dim mm As Boolean
Dim nn As Worksheet
Dim xx As Range
Dim yy As String

On Error Resume Next
yy = ActiveWindow.RangeSelection.Address
Set xx = Application.InputBox("Insert a range:", "Microsoft Excel", yy, , , , , 8)
If xx Is Nothing Then Exit Sub
Set nn = Worksheets("Output")
mm = Application.ScreenUpdating
Application.ScreenUpdating = False
xx.Copy
nn.Cells(Rows.Count, 2).End(xlUp).Offset(11, 0).PasteSpecial xlPasteValues
Application.CutCopyMode = False
Application.ScreenUpdating = mm

End Sub
  • Press Save or Ctrl + S.

Copy the Contents of a Row and Paste Values to the Next Empty Row in Another Worksheet Using Excel VBA

  • Hit the F5 button to run to code.
  • A dialog box will appear.
  • Insert a cell range that you want to copy and hit OK.

  • You will get the output in the “Output” worksheet.

Read More: Excel VBA: Copy Cell Value and Paste to Another Cell


Download Practice Workbook

You can download the Excel file from the following link and practice along.


Related Articles

Get FREE Advanced Excel Exercises with Solutions!
Mrinmoy Roy
Mrinmoy Roy

Mrinmoy Roy, a dedicated professional with a BSc in Electronics and Communication Engineering from Khulna University of Engineering & Technology, Bangladesh, brings over two years of expertise to the ExcelDemy project. As a prolific contributor, he has authored around 180 articles, showcasing his deep knowledge and passion for Microsoft Excel, Data Analysis, and VBA. His unwavering commitment to continuous learning, combined with versatile skills, renders him well-suited for roles in data management and spreadsheet solutions. He has interest... Read Full Bio

2 Comments
  1. Hello, is there anyway to insert text in several sheets at the same time, not just the “output”-sheet?

    • Hi Michelle,
      You can try the following piece of code:

      Sub PasteAcrossSheets()

      Dim arr(3)

      i = 0
      For Each Worksheet In ActiveWorkbook.Sheets
      Worksheet.Activate
      arr(i) = ActiveSheet.Name
      i = i + 1
      Next

      yy = ActiveWindow.RangeSelection.Address
      Set xx = Application.InputBox(“Insert a range:”, “Microsoft Excel”, yy, , , , , 8)
      If xx Is Nothing Then Exit Sub

      mm = Application.ScreenUpdating
      Application.ScreenUpdating = False
      xx.Copy

      Sheets(arr).Select

      Range(“G5”).Select
      ActiveSheet.Paste

      Application.CutCopyMode = False
      Application.ScreenUpdating = mm

      End Sub

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo