comparing 2 tabs and returning matched data

ahs004

Board Regular
Joined
Jul 18, 2011
Messages
83
Hi all,

I have coded the below but it doesnt seem to be working.

It returns the values and rows but its not the same same data when i cross reference it.

The data i am comparing is unique reference number that differs from 3 digit to a 6 digit. i think it matches the first one that finds which contains that number. ie; if 33405 and returs 3405.

Is there a way that i can set it to return value on exact match?

Many thanks with your help.


Sub MatchResidents_martlet()
Dim i As Long, k As Long, n As Variant, r As Range
Application.ScreenUpdating = False
With Sheets("Martlet")
Set r = Range(.Cells(7, 18), .Cells(65536, 18).End(xlUp))
End With
k = 0
i = 1
While Not IsEmpty(Sheets("Sheet1").Cells(i, 7))
n = Application.Match(Sheets("Sheet1").Cells(i, 7).Value, r, 0)
If IsNumeric(n) Then
Sheets("Sheet1").Cells(i, 7).Interior.ColorIndex = 35
k = k + 1
Sheets("Martlet").Rows(n).Copy Sheets("Sheet2").Rows(k)
Else
Sheets("Sheet1").Cells(i, 7).Interior.ColorIndex = 3
End If
i = i + 1
Wend
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,224,586
Messages
6,179,707
Members
452,939
Latest member
WCrawford

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