davidmyers
Board Regular
- Joined
- Jan 29, 2017
- Messages
- 88
- Office Version
- 2016
- Platform
- 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:
At red line I get Run-Time error "13"
What am I doing wrong?
Thanks
David
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