Copy a row if it contains certain texts to another sheet

guypt86

New Member
Joined
Jun 25, 2021
Messages
5
Office Version
  1. 2019
Platform
  1. Windows
I'm using a code I found for copying several rows from sheet1 to sheet2 if one cell in column "A" contains 1 of 4 text options for example "name", "school", "class", "team"

The coding is pretty new to me. So I'm straggling to get the results I need:

As for the code I've found - everytime I run it, another (unnecessary) of the same rows are popping, and I'm not sure how to include the other 3 text condition.

The code I'm using:


Option Explicit

Sub Test()

Dim Cell As Range

With Sheets(1)
' loop column A untill last cell with value (not entire column)
For Each Cell In .Range("A1:A" & .Cells(.Rows.Count, "A").End(xlUp).Row)
If Cell.Value = "name" Then
' Copy>>Paste in 1-line (no need to use Select)
.Rows(Cell.Row).Copy Destination:=Sheets(2).Rows(Cell.Row)
End If
Next Cell
End With

End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
if you would provide sample data file or a minisheet this can eas;ly be done in Power query. no VBA neccesery.
 
Upvote 0

Forum statistics

Threads
1,214,424
Messages
6,119,400
Members
448,893
Latest member
AtariBaby

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