我正在寻找一种使用VBA删除评论中的空行的方法。我有一个Excel文件,其中包含大量已损坏的注释,包含空行,并且无法逐个浏览它们。
我没有在注释中找到编辑行的命令,也不知道从哪里开始,所以我没有任何代码向你们展示。但我正在思考:
For Each comment In ActiveSheet.Comments
"REMOVE EMPTY ROWS" <-- What to put here?
Next comment
希望你能帮助我!
编辑: 我的所有空行都在评论的末尾,如下所示:
答案 0 :(得分:3)
我找到了答案。它似乎不是空行,只是评论的大小以某种方式改变了。所以这段代码修好了它:
Sub Comments_AutoSize()
Dim MyComments As Comment
Dim lArea As Long
For Each MyComments In ActiveSheet.Comments
With MyComments
.Shape.TextFrame.AutoSize = True
If .Shape.Width > 300 Then
lArea = .Shape.Width * .Shape.Height
.Shape.Width = 200
.Shape.Height = (lArea / 200) * 1.1
End If
End With
Next
End Sub
答案 1 :(得分:1)
假设您的评论看起来像这样
你可以试试这个
Sub RemoveEmptyLinesInComments()
Dim c As Comment
For Each c In ActiveSheet.Comments
c.Text Text:=Replace(c.Text, vbLf, Chr(32))
Next c
End Sub
实现
好的,在您编辑了问题并使用提供的详细信息更改了含义后,我想出了另一个代码作为解决方案。试试
Sub RemoveEmptiesFromComments()
Dim c As Comment
For Each c In ActiveSheet.Comments
Dim v As Variant
v = Split(c.Text, Chr(32))
Dim i As Long, s As String
For i = LBound(v) To UBound(v) - 1
s = s & Chr(32) & v(i)
Next i
Dim rng As Range
Set rng = c.Parent
c.Delete
rng.AddComment Text:=s
rng.Comment.Shape.TextFrame.AutoSize = True
Next c
End Sub