compare two columns

naresh55

New Member
Joined
Apr 21, 2014
Messages
24
Hi All,

How to create VBA coding for I'm having data to compare in sheet 1 column B and C, if any mis matched value found it should be mention in sheet 2 as mention below

Input Sheet 1:
A B C
Customer Name ABC ABC
Part Number 2342 2342
Qty 50 100
Delivery Date 31.12.2016 31.12.2016
Net Price 9000 10000

<colgroup><col><col><col></colgroup><tbody>
</tbody>


Mismatch value to be publish n sheet 2 mention formate
Output in Sheet 2:

ABCDE F
s NOCustomer NamePart NumberQtyDelivery Date Net Price

<colgroup><col><col><col><col><col><col></colgroup><tbody>
</tbody>
100 10000
 

Some videos you may like

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

portews

Active Member
Joined
Sep 4, 2009
Messages
303
Assuming that the entire Sheet1 is formatted this way, with 5 rows of customer info and you want a row number to verify, try this:

Code:
Sub CompareCustomers()
[COLOR=#00ff00]'http://www.mrexcel.com/forum/excel-questions/981155-compare-two-columns.html[/COLOR]
Dim i As Integer
Dim j As Integer
Dim LastRowSht2 As Integer
[COLOR=#00ff00]'for each customer[/COLOR]
For i = 1 To Sheets(1).Cells(Sheets(1).Rows.Count, "A").End(xlUp).Row Step 5
[COLOR=#00ff00]    'find the last row in Sheet 2[/COLOR]
    LastRowSht2 = Sheets(2).Cells(Sheets(2).Rows.Count, "A").End(xlUp).Row + 1
[COLOR=#00ff00]    'loop thru the customer information[/COLOR]
    For j = 0 To 4
[COLOR=#00ff00]        'if cells in B don't match the adjacent cells in C[/COLOR]
        If Not Sheets(1).Cells(i + j, 2) = Sheets(1).Cells(i + j, 3) Then
[COLOR=#00ff00]            'print the customer row number in the A column[/COLOR]
            Sheets(2).Cells(LastRowSht2, 1) = i
[COLOR=#00ff00]            'print the information in C that does not match in the appropriate column[/COLOR]
            Sheets(2).Cells(LastRowSht2, j + 2) = Sheets(1).Cells(i + j, 2)
        End If
    Next
Next
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,655
Messages
5,597,384
Members
414,141
Latest member
Joey_T92

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
Top