Handling Match Error in VBA

mhp620

New Member
Joined
Jan 6, 2010
Messages
25
Can someone give me pointers on how to handle the error in VBA when there is NO match? The code below runs fine otherwise, though I suspect there are more efficient ways to go about this. Thanks in advance. Mike

Sub Beta_Report()
Dim LastCell As Long
Dim MatchRow As Long
Dim iCount As Integer
LastRow = Cells(Rows.Count, 2).End(3).Row
For iCount = 1 To LastRow
If Not IsEmpty(Sheets("AA-beta-F").Cells((11 + iCount), 2).Value) Then
LUFund = Sheets("AA-beta-F").Cells((11 + iCount), 2).Value
MatchRow = WorksheetFunction.Match(LUFund, Sheets("Summary").Range("B:B"), 0)
Sheets("AA-beta-F").Cells((11 + iCount), 1).Value = MatchRow
Sheets("AA-beta-F").Cells((11 + iCount), 11).Value = Sheets("Summary").Cells(MatchRow, 9).Value
Sheets("AA-beta-F").Cells((11 + iCount), 15).Value = Sheets("Summary").Cells(MatchRow, 12).Value
Sheets("AA-beta-F").Cells((11 + iCount), 17).Value = Sheets("Summary").Cells(MatchRow, 10).Value
Else
End If
Next iCount
End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Perhaps try this:

Rich (BB code):
Sub Beta_Report()
Dim LastCell As Long
Dim MatchRow As Variant
Dim iCount As Integer
LastRow = Cells(Rows.Count, 2).End(3).Row
For iCount = 1 To LastRow
  If Not IsEmpty(Sheets("AA-beta-F").Cells((11 + iCount), 2).Value) Then
    LUFund = Sheets("AA-beta-F").Cells((11 + iCount), 2).Value
    MatchRow = Application.Match(LUFund, Sheets("Summary").Range("B:B"), 0)    
      If Not IsError(MatchRow) Then
        Sheets("AA-beta-F").Cells((11 + iCount), 1).Value = MatchRow
        Sheets("AA-beta-F").Cells((11 + iCount), 11).Value = Sheets("Summary").Cells(MatchRow, 9).Value
        Sheets("AA-beta-F").Cells((11 + iCount), 15).Value = Sheets("Summary").Cells(MatchRow, 12).Value
        Sheets("AA-beta-F").Cells((11 + iCount), 17).Value = Sheets("Summary").Cells(MatchRow, 10).Value
      End If

    End If
Next iCount
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,843
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