Table of Contents
VBA (Visual Basic for Applications) is a programming language that can be used in Microsoft Excel to automate tasks and manipulate data. One useful application of VBA is to copy rows from one sheet to another based on specific criteria. This means that users can specify certain conditions or criteria, and VBA will automatically copy the rows that meet those criteria from one sheet to another. This can save time and effort, especially when dealing with large amounts of data. By using VBA, users can streamline their data management process and improve efficiency in their Excel tasks.
VBA: Copy Rows to Another Sheet Based on Criteria
You can use the following syntax in VBA to copy each row in one sheet that meets specific criteria to another sheet:
Sub CopyToAnotherSheet()
Dim LastRow As Long
'Find last used row in a Column A of Sheet1With Worksheets("Sheet1")
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With'Find first row where values should be posted in Sheet2With Worksheets("Sheet2")
j = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
End With'Paste each row that contains "Mavs" in column A of Sheet1 into Sheet2For i = 1 To LastRow
With Worksheets("Sheet1")
If .Cells(i, 1).Value = "Mavs" Then
.Rows(i).Copy Destination:=Worksheets("Sheet2").Range("A" & j)
j = j + 1
End IfEnd WithNext i
End Sub
This particular macro will copy each row in Sheet1 where column A is equal to “Mavs” and paste each of these rows into the next available rows in Sheet2.
The following example shows how to use this syntax in practice.
Example: Copy Rows to Another Sheet Based on Criteria Using VBA
Suppose we have the following dataset in Sheet1 that contains information about various basketball players:

And suppose we have the following dataset in Sheet2:

Notice that Sheet2 only contains data for players on the Warriors team.
Suppose we would like to copy each row in Sheet1 where the Team column is equal to Mavs and paste each of these rows in the next available rows in Sheet2.
We can create the following macro to do so:
Sub CopyToAnotherSheet()
Dim LastRow As Long
'Find last used row in a Column A of Sheet1With Worksheets("Sheet1")
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With'Find first row where values should be posted in Sheet2With Worksheets("Sheet2")
j = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
End With'Paste each row that contains "Mavs" in column A of Sheet1 into Sheet2For i = 1 To LastRow
With Worksheets("Sheet1")
If .Cells(i, 1).Value = "Mavs" Then
.Rows(i).Copy Destination:=Worksheets("Sheet2").Range("A" & j)
j = j + 1
End IfEnd WithNext i
End SubWhen we run this macro, we receive the following output in Sheet2:

Notice that each row in Sheet1 where the Team name was equal to Mavs has been pasted into the next available rows in Sheet2.
Note: You can find the complete documentation for the VBA Copy method .
Cite this article
stats writer (2024). How can I use VBA to copy rows from one sheet to another based on specific criteria?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-use-vba-to-copy-rows-from-one-sheet-to-another-based-on-specific-criteria/
stats writer. "How can I use VBA to copy rows from one sheet to another based on specific criteria?." PSYCHOLOGICAL SCALES, 23 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-i-use-vba-to-copy-rows-from-one-sheet-to-another-based-on-specific-criteria/.
stats writer. "How can I use VBA to copy rows from one sheet to another based on specific criteria?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-use-vba-to-copy-rows-from-one-sheet-to-another-based-on-specific-criteria/.
stats writer (2024) 'How can I use VBA to copy rows from one sheet to another based on specific criteria?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-use-vba-to-copy-rows-from-one-sheet-to-another-based-on-specific-criteria/.
[1] stats writer, "How can I use VBA to copy rows from one sheet to another based on specific criteria?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.
stats writer. How can I use VBA to copy rows from one sheet to another based on specific criteria?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
