Compare Two Non-Adjacent Columns in a Sheet to Two Non-Adjacent Columns on Another Sheet

NorthbyNorthwest

Board Regular
Joined
Oct 27, 2013
Messages
147
Office Version
  1. 365
I found this code posted by Sixthsense in March 2014 onanother Mr. Excel thread on comparing two columns of data on a worksheet to twocolumns of data on another worksheet. Italmost works for me. My problem is mycolumns are not adjacent on either worksheet. Is there a way this code could be rewritten to compare column M in Sheet1 to column C in Sheet 2 and column P in Sheet 1 to column J in Sheet 2. See Sixthsense’s code:<o:p></o:p>
<o:p> </o:p>
Sub CheckAvailability()<o:p></o:p>
Dim rMyRng As Range, rCompare As Range, r As Range, lFoundAs Long, blStatus As Boolean<o:p></o:p>
<o:p> </o:p>
Application.ScreenUpdating = False<o:p></o:p>
<o:p> </o:p>
With Sheets("Sheet1")<o:p></o:p>
Set rMyRng =.Range("A1:B" & Range("B" &Rows.Count).End(xlUp).Row)<o:p></o:p>
End With<o:p></o:p>
<o:p> </o:p>
With Sheets("Sheet2")<o:p></o:p>
Set rCompare =.Range("A1:B" & Range("B" &Rows.Count).End(xlUp).Row)<o:p></o:p>
End With<o:p></o:p>
<o:p> </o:p>
For Each r In rMyRng.Rows<o:p></o:p>
With r<o:p></o:p>
.Select<o:p></o:p>
blStatus =False<o:p></o:p>
lFound =Application.CountIfs(rCompare.Columns(1), .Cells(1).Value, rCompare.Columns(2),.Cells(2).Value)<o:p></o:p>
If lFound ThenblStatus = True<o:p></o:p>
.Cells(2).Offset(, 1).Value = blStatus<o:p></o:p>
End With<o:p></o:p>
Next r<o:p></o:p>
<o:p></o:p>
Application.ScreenUpdating = True<o:p></o:p>
<o:p></o:p>
End Sub<o:p></o:p>
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,203,145
Messages
6,053,746
Members
444,681
Latest member
Nadzri Hassan

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