PC Review


Reply
Thread Tools Rate Thread

Compare two columns in a different worksheet

 
 
Denys
Guest
Posts: n/a
 
      7th Dec 2009
Good day everyone,

With the following code, you compare data between two columns in a
different worksheet, and the results are transferred to a third one.

Sub test()

Dim T(), A As Long
Dim Rg As Range, Rg1 As Range
With Worksheets("month")
Set Rg = .Range("B1:B" & .Range("B65536").End(xlUp).Row)
End With


With Worksheets("Data received")
Set Rg1 = .Range("A1:A" & .Range("A65536").End(xlUp).Row)
End With


For Each c In Rg

If Application.CountIf(Rg1, c) = 0 Then
ReDim Preserve T(A)
T(A) = c.Value
A = A + 1
End If
Next
Worksheets("Result").Range("A1").Resize(UBound(T) + 1) = _
Application.Transpose(T)

End Sub

However, I would like to have the entire row to show on the
destination sheet rather than the cell value only.

Anyone would know where I should modify the code ?

Thanks for your time

Denys
 
Reply With Quote
 
 
 
 
marcus
Guest
Posts: n/a
 
      7th Dec 2009
Hi Denys

This will do the job for you. Originally you were placing the
outcomeof Rg in Col A of the "Result" sheet. If you copy the entire
Column of the Cells which do not match, the outcome will appear in
Column b of the "Result" sheet. Not sure if this is what you want?

Take Care

Marcus



Sub test()


Dim T(), A As Long
Dim Rg As Range, Rg1 As Range
Dim lw as Long
lw = Sheets("Result").Range("B" & Rows.Count).End(xlUp).Row + 1
With Worksheets("month")
Set Rg = .Range("B1:B" & .Range("B65536").End(xlUp).Row)
End With


With Worksheets("Data received")
Set Rg1 = .Range("A1:A" & .Range("A65536").End(xlUp).Row)
End With


For Each c In Rg

If Application.CountIf(Rg1, c) = 0 Then
ReDim Preserve T(A)
'T(A) = c.Value
A = A + 1
c.EntireRow.Copy Sheets("Result").Range("A" & lw)
lw = lw + 1
End If
Next
'Worksheets("Result").Range("A1").Resize(UBound(T) + 1) = _
Application.Transpose(T)

End Sub

 
Reply With Quote
 
Denys
Guest
Posts: n/a
 
      7th Dec 2009
Hi Marcus,

Thank you very much....it's perfect !!!

Wow !!

Have a nice day

Denys
 
Reply With Quote
 
Tim Zych
Guest
Posts: n/a
 
      7th Dec 2009
You already have an answer, but for more general Excel comparison you might
be interested in my Excel utility "Workbook Compare". It was conceived as a
platform for regression testing, but can be used for virtually any Excel
comparison needs whatsoever.

--
Regards,
Tim Zych
http://www.higherdata.com
Workbook Compare - Excel data comparison utility


"Denys" <(E-Mail Removed)> wrote in message
news:4834e4f4-6634-44e7-aa23-(E-Mail Removed)...
> Good day everyone,
>
> With the following code, you compare data between two columns in a
> different worksheet, and the results are transferred to a third one.
>
> Sub test()
>
> Dim T(), A As Long
> Dim Rg As Range, Rg1 As Range
> With Worksheets("month")
> Set Rg = .Range("B1:B" & .Range("B65536").End(xlUp).Row)
> End With
>
>
> With Worksheets("Data received")
> Set Rg1 = .Range("A1:A" & .Range("A65536").End(xlUp).Row)
> End With
>
>
> For Each c In Rg
>
> If Application.CountIf(Rg1, c) = 0 Then
> ReDim Preserve T(A)
> T(A) = c.Value
> A = A + 1
> End If
> Next
> Worksheets("Result").Range("A1").Resize(UBound(T) + 1) = _
> Application.Transpose(T)
>
> End Sub
>
> However, I would like to have the entire row to show on the
> destination sheet rather than the cell value only.
>
> Anyone would know where I should modify the code ?
>
> Thanks for your time
>
> Denys



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
compare two columns in same worksheet for similarities Cynthia Microsoft Excel Worksheet Functions 2 10th Feb 2009 08:53 PM
Compare 2 worksheets all 6 columns in each worksheet Bud Microsoft Excel Worksheet Functions 7 25th Sep 2008 02:26 PM
compare two columns within a worksheet, then highlight duplicates =?Utf-8?B?YmV0aA==?= Microsoft Excel Worksheet Functions 1 20th Sep 2006 03:47 PM
How do I Compare worksheet columns =?Utf-8?B?ZGFubml4NTQ=?= Microsoft Excel Worksheet Functions 8 9th May 2005 02:26 AM
Compare 2 columns in a worksheet. Neeraja Microsoft Excel Worksheet Functions 2 17th Sep 2003 03:42 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:40 PM.