Copy and paste rows that contain certain text to a seperate tab VBA beginner

VBAlearner1

New Member
Joined
Apr 11, 2013
Messages
4
Hi

I'd appreciate some help. I know excel quite well but I'm new to VBA.

I'd like a code that copy and pastes complete rows from sheet 1 to sheet 2, however I only want to copy and paste the rows that have certain text (the number 1) in column G.

Can anyone help please?
 
Another approach ... put the following code into the code module for your worksheet (not into a regular module).\
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("G:G")) Is Nothing Then Exit Sub
    If Target = "1" Then
        Target.EntireRow.Copy Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
    End If
End Sub


Love the code!

Can you please help me out and edit the code to filter out certain characters in the cell?

Like if it already contains a 1 in any part, it will copy the row to the next sheet?

MUCH appreciated! :)
 
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Maybe:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("G:G")) Is Nothing Then Exit Sub
    If Target Like "*1*" Then
        Target.EntireRow.Copy Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
    End If
End Sub
 
Upvote 0
Maybe:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("G:G")) Is Nothing Then Exit Sub
    If Target Like "*1*" Then
        Target.EntireRow.Copy Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
    End If
End Sub

That works!! Now all I need is to copy the row above the one with the target text... If you can can help me with that pleaseeeee.
 
Upvote 0
Try:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("G:G")) Is Nothing Then Exit Sub
    If Target Like "*1*" Then
        Cells(Target.Row - 1, 1).EntireRow.Copy Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,698
Members
448,979
Latest member
DET4492

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