WorksheetFunction.Match Question

brans1982

Active Member
Joined
Mar 25, 2009
Messages
263
Hi,

Please see example data below...

Sub MatchValue()
Dim wf As WorksheetFunction, _
rng As Range

Set wf = Application.WorksheetFunction
Set rng = Range("A1:A2000")

FinalRow = Cells(Rows.Count, 2).End(xlUp).Row
PasteRow = Cells(Rows.Count, 4).End(xlUp).Row

For i = 1 To FinalRow

If IsError(wf.Match(Cells(i, 2), rng, 0)) Then

Cells(i, 2).Copy Destination:=Cells(PasteRow, 4)
PasteRow = PasteRow + 1

End If

Next i

End Sub

Using normal formulas I would use the MATCH function like this...

=IF(ISERROR(MATCH(A1,B1:B10,0)),"No Match","Match")

...to find if there is certain data in a column but when trying something similar in VBA, when the code does find a value that isn't in the MATCH range, it throws an error instead of following on with e.g Copy/Paste like in the VBA code above.

Is there anyway around this?

I'm not to up on Error handlers, but I've tried Resume Next ect. but to no avail.

Thanks!
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
I think I have it...

I used Application.Match instead of Application.WorksheetFunction.Match

Why does this work?
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,853
Members
452,948
Latest member
UsmanAli786

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