我正在尝试使用来自另一个相关问题的宏(Excel 宏 - 到逗号分隔单元格的行(保留/聚合列))并且收到运行时错误 1004。
尝试调试时,它说这一行是问题所在: oCell.Offset(-1, 1).Value = sResult
这是宏:
子 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**
结束子