Automatic select, copy and paste

Fenrir96

New Member
Joined
Jun 15, 2017
Messages
1
I am wondering if there is a way to search for a specific value in a column; then if the value is found highlight the entire row and copy it to another sheet or workbook. I know that you can do this manually, I was just curious if there was a way or writing a line of code or a string of macros so that for each new value I need I can simply edit the string and have it do the rest for me.

The way I think it would run would be if value in column is equal to RED then select entire row. When entire row is selected copy and past to location X. If column is not equal to Red then do nothing.

Hopefully that explanation made as much sense as it did to me,
Thanks
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
This is sample code.
Find "RED" in columnA of Sheet1 then copy to Sheet2.

Code:
Sub red()
Dim tgt As String
Dim ws1 As Worksheet, ws2 As Worksheet
Dim LR As Long, LR1 As Long, i As Long
Set ws1 = Sheets("Sheet1")
Set ws2 = Sheets("Sheet2")
LR1 = ws2.cells(Rows.Count, 1).End(xlUp).Row + 1
With ws1
    LR = .cells(Rows.Count, 1).End(xlUp).Row
    For i = 2 To LR
        If .cells(i, 1).Value = "RED" Then
            .Rows(i).EntireRow.copy ws2.Rows(LR1)
            LR1 = LR1 + 1
        End If
    Next
End With
MsgBox "Done"
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,520
Members
449,088
Latest member
RandomExceller01

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