excel macro to combine B column cells based on A Column
I am trying to use a macro from another related question (Excel Macro -
Rows to Comma Separated Cells (Preserve/Aggregate Column)) and am getting
a Runtime Error 1004.
When trying to debug, it says that this line is the problem:
oCell.Offset(-1, 1).Value = sResult
Here is the macro:
Sub GroupMyValues()
Dim oCell As Excel.Range
Dim sKey As String
Dim sResult As String
Set oCell = Worksheets(2).Range("A1")
While Len(oCell.Value) > 0
If oCell.Value <> sKey Then
'If first entry, no rows to be deleted
If sKey <> "" Then
oCell.Offset(-1, 1).Value = sResult
End If
sKey = oCell.Value
sResult = oCell.Offset(0, 1).Value
Set oCell = oCell.Offset(1, 0)
Else
sResult = sResult & ", " & oCell.Offset(0, 1).Value
Set oCell = oCell.Offset(1, 0)
oCell.Offset(-1, 0).EntireRow.Delete
End If
Wend
'Last iteration
**oCell.Offset(-1, 1).Value = sResult**
End Sub
No comments:
Post a Comment