Macro to tell me if two coulmns are the same

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,210
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi everyone,

if it possible id like a macro that does this

Compares Sheet("Data1") Column J to Sheet("data2") column D
if both columns are identical put then
Sheet("Data1") cell M1 = Yes, if not = No

can this be done?

please help if you can

Thanks

Tony
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
is it just they sum the same, because sorting will make them different
 
Upvote 0
Code:
Sub MatchCol()
Dim r1 As Range, r2 As Range, cel As Range, d1$, d2$
With Sheets("Data1")
    Set r1 = .Range("J1:J" & .Cells(Rows.Count, "J").End(3))
End With
With Sheets("Data2")
    Set r2 = .Range("D1:D" & .Cells(Rows.Count, "D").End(3))
End With
For Each cel In r1
    d1 = d1 & cel
Next
For Each cel In r2
    d2 = d2 & cel
Next
If d1 = d2 Then
    Sheets("Data1").[M1] = "Yes"
Else: Sheets("Data1").[M1] = "No"
End If
End Sub
 
Upvote 0
Correction :
Code:
Sub MatchCol()
Dim r1 As Range, r2 As Range, cel As Range, d1$, d2$
With Sheets("Data1")
    Set r1 = .Range("J1:J" & .Cells(Rows.Count, "J").End(3)[COLOR=#ff0000].Row[/COLOR])
End With
With Sheets("Data2")
    Set r2 = .Range("D1:D" & .Cells(Rows.Count, "D").End(3)[COLOR=#ff0000].Row[/COLOR])
End With
For Each cel In r1
    d1 = d1 & cel
Next
For Each cel In r2
    d2 = d2 & cel
Next
If d1 = d2 Then
    Sheets("Data1").[M1] = "Yes"
Else: Sheets("Data1").[M1] = "No"
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

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