Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 4
Default Copy data that matches criteria in one worksheet to another worksh

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
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,520
Default Copy data that matches criteria in one worksheet to another worksh

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
---------------
Jacob Skaria


"angiec50" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy from sheet to sheet when matches criteria jeremiah Excel Worksheet Functions 2 June 2nd 09 01:05 PM
copy if data matches [email protected] Excel Worksheet Functions 3 April 17th 08 11:47 PM
Selecting data that matches certain criteria in one column Anthony Excel Discussion (Misc queries) 7 May 17th 07 12:48 PM
How can I get data from one worksheet into another exsiting worksh Sabrina Excel Discussion (Misc queries) 2 August 30th 05 09:01 PM
How do I give all access to one worksheet but not to other worksh. B Fraissinet Excel Worksheet Functions 1 January 12th 05 06:37 AM


All times are GMT +1. The time now is 10:58 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"