comparision

jackgn

New Member
Joined
May 20, 2011
Messages
17
Hi all,

the below code compare the values from sheet1 and sheet2 and display the result is sheet3 which is present in sheet1 and sheet2, actually i need a code where it should compare the value from sheet1 and if it is not present in sheet2 then the result sholuld present in sheet3 can any one help in this.
Option Explicit
Sub Comparew2w1()
Dim w1 As Worksheet, w2 As Worksheet, w3 As Worksheet
Dim c As Range, FR As Long, NR As Long
Application.ScreenUpdating = False
Set w1 = Worksheets("Sheet1")
Set w2 = Worksheets("Sheet2")
Set w3 = Worksheets("Sheet3")
w3.Columns(1).ClearContents
NR = 0
For Each c In w2.Range("A1", w2.Range("A" & Rows.Count).End(xlUp))
FR = 0
On Error Resume Next
FR = Application.Match(c, w1.Columns(1), 0)
On Error GoTo 0
If FR > 0 Then
NR = NR + 1
w3.Cells(NR, 1).Value = c
End If
Next c
w3.Columns(1).AutoFit
w3.Activate
End Sub

</PRE>
 
Last edited:

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hi

How about...

(Untested!)

Code:
Sub Test()
    Dim Rng1 As Range, Rng2 As Range, rCell As Range
    Dim WS As Worksheet
    Set Rng1 = Sheets("Sheet1").Range("A2:A" & Sheets("Sheet1").Range("A" & Sheets("Sheet1").Rows.Count).End(xlUp).Row)
    Set Rng2 = Sheets("Sheet2").Range("A2:A" & Sheets("Sheet2").Range("A" & Sheets("Sheet2").Rows.Count).End(xlUp).Row)
    Set WS = Sheets("Sheet3")
    With WS
        For Each rCell In Rng1
            If Not IsNumeric(Application.Match(rCell.Value, Rng2, 0)) Then
                .Range("A" & .Rows.Count).End(xlUp).Offset(1).Value = rCell.Value
            End If
        Next rCell
    End With
End Sub
 
Upvote 0
Hi, Sorry actually it is exactly comparing the value like sheet1 A1 cell with sheet2 A cell, then it is extracting if the same value is present in A2 cell it is not comparing, can you please help me to compare the complete sheet1 with sheet2 from A1 to A65536.
Thanks
Jackgn
 
Upvote 0
sorry for the above post,
Hi,
thx for the above macro, it compare the value from sheet1 and if it is not present in sheet2 then the result present in sheet3 also i need a macro along with this where it should compare vise-versa also..,
i can paste the sheet2 value in sheet1 to get the result, but i need a macro to compare both the sheets. can any one help me on this, thx in advace.
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,834
Members
452,947
Latest member
Gerry_F

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