run-time error 13 after Application.Match

davidmyers

Board Regular
Joined
Jan 29, 2017
Messages
88
Office Version
  1. 2016
Platform
  1. Windows
Hi,
I'm trying to create a comma separated list in colD from terms in colA where colB and colC match.
I have the following code:
Code:
Sub test2()    Dim r1 As Range
    Dim r2 As Range
    Dim cell As Range
    Dim lastrow As Long
    Dim csvTxt As String
    'change Sheet1 to suit
    With ThisWorkbook.Worksheets("Sheet5")
        lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
        Set r1 = .Range("A2:A" & lastrow)
    End With


    'change Sheet2 to suit
    With ThisWorkbook.Worksheets("Sheet5")
        lastrow = .Cells(.Rows.Count, "C").End(xlUp).Row
        Set r2 = .Range("C2:C" & lastrow)
    End With


    For Each cell In r1
        If Not (IsError(Application.Match(cell.Offset(0, 1).Value, r2, 0))) Then
[COLOR=#ff0000]            If r2.Offset(0, 1).Value > " " Then[/COLOR]
                r2.Offset(0, 1) = r2.Offset(0, 1).Value & ", "
            End If
            r2.Offset(0, 1) = r2.Offset(0, 1).Value & cell.Value
        End If
    Next cell
End Sub

At red line I get Run-Time error "13"

What am I doing wrong?

Thanks
David
 
Where do I mark as solved? - thought it was under Thread Tools but it 'aint
 
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Forum statistics

Threads
1,216,028
Messages
6,128,395
Members
449,446
Latest member
CodeCybear

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