Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Old May 23rd 07, 05:41 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Jan 2007
Posts: 220
Default Compare 2 Ranges, Copy/Paste Row on Match

I'm trying to compare the values in 2 ranges and if found, copy the
entire row to a new worksheet.

This is what I've come up with but it's not working:
'----

Set ws = Worksheets.Add

count = 1

For Each i In rng1
For Each x In rng2
If i.Value = x.Value Then
i.EntireRow.Copy ws.Rows(count)
count = count + 1
End If
Next x
Next i

'---

Thanks,
-- Dan


  #2   Report Post  
Old May 23rd 07, 06:20 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Jul 2006
Posts: 9,101
Default Compare 2 Ranges, Copy/Paste Row on Match

Your code is comparing every value in rng1 with every value in rng2. I think
you only want to compare items in same row

For Each i In rng1
If i.Value = i.offset(rowoffset:= 0, columnoffset:= 6).Value Then
i.EntireRow.Copy ws.Rows(count)
count = count + 1
End If
Next i


or something like this

for rowcount = 1 to Lastrow

If cells(rowcount, "i") = cells(rowcount,"x") then

cells(rowcount, "i").EntireRow.Copy ws.Rows(count)

end if


next rowcount

"Dan R." wrote:

I'm trying to compare the values in 2 ranges and if found, copy the
entire row to a new worksheet.

This is what I've come up with but it's not working:
'----

Set ws = Worksheets.Add

count = 1

For Each i In rng1
For Each x In rng2
If i.Value = x.Value Then
i.EntireRow.Copy ws.Rows(count)
count = count + 1
End If
Next x
Next i

'---

Thanks,
-- Dan




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
Compare Col A and Col M, if Match, Copy Col N to Col E ryguy7272 Excel Worksheet Functions 1 March 21st 08 05:57 PM
Compare col and match then copy and paste saman110 via OfficeKB.com Excel Discussion (Misc queries) 2 February 21st 08 01:28 AM
Compare ranges n copy at bottom of first range Kaza Sriram Excel Programming 0 August 5th 04 02:16 PM
compare two ranges in different workbooks and copy data to a new workbook Kaza Sriram Excel Programming 7 August 2nd 04 05:04 PM
How do i compare values from two sheet and copy & paste if values match? rozb Excel Programming 0 March 5th 04 01:06 AM


All times are GMT +1. The time now is 02:23 AM.

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

About Us

"It's about Microsoft Excel"

 

Copyright © 2017