我正在创建一个宏,它将一个注释列的一部分连接到一个列中。当前,它正在正确运行,但是如果该行中只有一个注释,它将把单元格扩展到最大注释行的长度。例如,我的第一行有1条评论,但我的下一行有5条评论。然后,第一行变成1条注释,其后返回5个回车符。如果可能的话,我想跳到下一行。我不确定如何执行此操作,并尝试了多种方法。
此外,如果可能的话,我想改变评论的顺序(但这不是必须的)。
如果有任何疑问,欢迎提供任何帮助。
谢谢
Dim a, b, i As Long, y As Long, n As Long
a = Cells(1).CurrentRegion.Value
ReDim b(1 To UBound(a, 1), 1 To UBound(a, 2))
With CreateObject("Scripting.Dictionary")
.CompareMode = 1
For y = 2 To UBound(a, 2)
If Not .exists(a(1, y)) Then .Item(a(1, y)) = .Count + 2
Next
ReDim b(1 To UBound(a, 1), 1 To .Count + 1)
For y = 1 To 1
b(1, y) = a(1, y)
Next
For y = 0 To .Count - 1
b(1, y + 2) = .keys()(y)
Next
For i = 2 To UBound(a, 1)
For y = 1 To 1
b(i, y) = a(i, y)
Next
For y = 2 To UBound(a, 2)
b(i, .Item(a(1, y))) = b(i, .Item(a(1, y))) & IIf(b(i, .Item((1, y))) <> "", "", "") & a(i, y) & vbCrLf
' If you want to reverse order of comments reverse how you append to string^^^^^^
Next
Next
End With
'Joins together the comments section
Sheets.Add.Cells(1).Resize(UBound(b, 1), 11 + n - 1).Value = b
Cells(1).Resize(UBound(b, 1), UBound(b, 2)).Value = b
ActiveSheet.Name = "WS"