Copy data that matches criteria in one worksheet to another worksh

A

angiec50

Hi
I am needing to be able to search through a column of data in Worksheet 1
and copy the matched and corresponding data to another worksheet starting at
row 4.

The code that I have already used is:

Sub cond_copy()
Sheets("Sheet1").Select
rowcount = Cells(Cells.Rows.Count, "a").End(xlUp).Row
For i = 1 To rowcount
Range("a" & i).Select
check_value = ActiveCell
If check_value = "True" Or check_value = "true" Then
ActiveCell.EntireRow.Copy
Sheets("Sheet2").Select
rowcount = Cells(Cells.Rows.Count, "a").End(xlUp).Row
Range("a" & rowcount + 1).Select
ActiveSheet.Paste
Sheets("Sheet1").Select
End If
Next
End Sub

This seems to work fine, apart from that it pastes the data and overwrites
my heading in Row 2 of Worksheet 2. Where and what do I need to write to
ensure that the copied data is placed in the correct position i.e. Row 4 on
Sheet 2

Thanks in advanced for your help
 
J

Jacob Skaria

Try the below..

Sub cond_copy()
Dim ws As Worksheet, lngRow As Long, lngNRow As Long
lngNRow = 4
Set ws = Sheets("Sheet2")
For lngRow = 1 To Cells(Rows.Count, "A").End(xlUp).Row
If UCase(Range("A" & lngRow).Text) = "TRUE" Then
Rows(lngRow).Copy ws.Rows(lngNRow): lngNRow = lngNRow + 1
End If
Next
End Sub

If this post helps click Yes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top