How to Copy Rows to Another Worksheet Based on Criteria by Excel VBA: 2 Ways

Method 1 – Copy Rows To Another Worksheet Based on Text Criteria

➤ Press ALT+F11 to open the VBA window.

In the VBA window,

➤ Click the Insert tab and select Module.

module

It will open the Module(Code) window. Now,

➤ Insert the following code in the Module(Code) window,

Sub Copy_Criteria_Text()

Application.ScreenUpdating = False
With ActiveSheet
    .AutoFilterMode = False
    With Range("C1", Range("C" & Rows.Count).End(xlUp))
        .AutoFilter 1, "Virginia"
        On Error Resume Next
        .Offset(1).EntireRow.Copy Sheet3.Range("A" & Rows.Count).End(xlUp).Offset(1)
    End With
    .AutoFilterMode = False
End With
Application.ScreenUpdating = True
Sheet3.Select

End Sub

The code will create a Macro named  Copy_Criteria_Text  that searches for Virginia in column C of the current worksheet and returns the rows that contain Virginia in the worksheet Area Sales (Sheet3).

excel vba copy rows to another worksheet based on criteria

After that,

➤ Close or minimize the VBA window.

➤ Press ALT+F8.

It will open the Macro window.

➤ Select Copy_Criteria_Text in the Macro name box and click on Run.

excel vba copy rows to another worksheet based on criteria

The rows with Virginia will be copied in the worksheet named Area Sales

excel vba copy rows to another worksheet based on criteria


Method 2 – Copy Rows to Another Worksheet Based on Number Criteria

➤ Press ALT+F11 to open the VBA window.

In the VBA window,

➤ Click the Insert tab and select Module.

vba window

It will open the Module(Code) window. Now,

➤ Insert the following code in the Module(Code) window,

Sub Copy_Criteria_Number()

Application.ScreenUpdating = False
With ActiveSheet
    .AutoFilterMode = False
    With Range("D1", Range("D" & Rows.Count).End(xlUp))
        .AutoFilter 1, ">100000"
        On Error Resume Next
        .Offset(1).EntireRow.Copy Sheet4.Range("A" & Rows.Count).End(xlUp).Offset(1)
    End With
    .AutoFilterMode = False
End With
Application.ScreenUpdating = True
Sheet4.Select

End Sub

The code will create a Macro named  Copy_Criteria_Number  that will search for values greater than 100000 in column D of the worksheet named Data and return the rows that contain sales values more than $100000  in the worksheet named Top Sales (Sheet4).

excel vba copy rows to another worksheet based on criteria

After that,

➤ Close or minimize the VBA window.

➤ Press ALT+F8.

It will open the Macro window.

➤ Select Copy_Criteria_Number in the Macro name box and click on Run.

excel vba copy rows to another worksheet based on criteria

The rows that contain sales values of more than $100000 will be copied into the Top Sales worksheet.

excel vba copy rows to another worksheet based on criteria

 


Download Practice Workbook


Related Articles

Get FREE Advanced Excel Exercises with Solutions!
Prantick Bala
Prantick Bala

PRANTICK BALA is a marine engineer who loves exploring Excel and VBA programming. Programming, to him, is a time-saving tool for efficiently managing data, files, and internet tasks. He is proficient in Rhino3D, Maxsurf, C++, MS Office, AutoCAD, Excel, and VBA and goes beyond the basics. Armed with a B.Sc in Naval Architecture & Marine Engineering from BUET, he has transitioned into the role of a content developer. Beyond his work, find him immersed in books, exploring new... Read Full Bio

4 Comments
  1. I understand the demonstration. However, my question is to take the information from the master sheet in a workbook and place it on another sheet with the same catagory within the same workbook. How can that be done?

  2. Awesome. How would this be modified to paste the row into a new row of an existing table on another worksheet?

    • Reply Avatar photo
      Naimul Hasan Arif Nov 20, 2022 at 4:57 PM

      Thanks SARAH for your comment and appreciation.
      You can use the following VBA code with necessary changes to apply your code.

      Sub AddRowFromAnotherSheet()
      Sheets(“sheet1”).Range(“B7:E7”).Copy Sheets(“sheet3”).Range(“B9:E9”)
      End Sub

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo