Copy a row to new sheet when cell in first column has specific text

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Copy a row to new sheet when cell in first column has specific text



I want to copy rows from sheet1 only when the cell in column B has a specific value which is a string. I used the code below, which seems to copy the rows, but just pastes empty cells in the new sheet.



I think the problem is that it is looking for a value, not a string (can a string be a value?). Do I need to define the cell as a string? Sorry if these are silly questions - new to coding.


Sub copy_rows()
Sheets.Add After:=Sheets(1)
Sheets(2).Name = "New"
For Each cell In Sheets(1).Range("B:B")
If cell.Value = "exampleword" Then
matchRow = cell.Row
Rows(matchRow & ":" & matchRow).Select
Selection.Copy
Sheets("New").Select
ActiveSheet.Rows(matchRow).Select
ActiveSheet.Paste
End If
Next
End Sub



Thanks









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard