Compare Two columns in Excel and find out missing one, VBA MACRO help

Jyotirmaya

Board Regular
Joined
Dec 2, 2015
Messages
204
Office Version
  1. 2019
Platform
  1. Windows
I have two columns A & B and have data from A1:A20, B1:B20
I am using the following code

1.Column C =IF(ISERROR(NOT(MATCH(A1:A20,$B$1:$B$20,0))),A1,"")
2.Column D =IF(ISERROR(NOT(MATCH(B1:B20,$A$1:$A$20,0))),B1,"")

In column C I am getting the missing numbers which I have there in Column A but not in Column B
In column D I am getting the missing numbers which I have there in Column B but not in Column A


I want a VBA macro code to do so.

what will be the code ?
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Try this:

Code:
Sub Jyotirmaya()
Dim i As Long

For i = 1 To 20
    If Len(Cells(i, 1)) <> 0 And Len(Cells(i, 2)) = 0 Then
        Cells(i, 3) = Cells(i, 1)
    ElseIf Len(Cells(i, 1)) = 0 And Len(Cells(i, 2)) <> 0 Then
        Cells(i, 4) = Cells(i, 2)
    End If
Next

End Sub
 
Last edited:
Upvote 0
Try this:

Code:
Sub Jyotirmaya()
Dim i As Long

For i = 1 To 20
    If Len(Cells(i, 1)) <> 0 And Len(Cells(i, 2)) = 0 Then
        Cells(i, 3) = Cells(i, 1)
    ElseIf Len(Cells(i, 1)) = 0 And Len(Cells(i, 2)) <> 0 Then
        Cells(i, 4) = Cells(i, 2)
    End If
Next

End Sub



Hello dear its not working
 
Upvote 0

Forum statistics

Threads
1,215,234
Messages
6,123,776
Members
449,123
Latest member
StorageQueen24

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