[英]Delete empty rows in comment in Excel using VBA
I'm looking for a way to delete empty rows in comments using VBA. 我正在寻找一种使用VBA删除注释中的空行的方法。 I have an Excel file with loads of corrupted comments, containing empty rows, and going through them one by one is not an option.
我有一个Excel文件,其中包含大量损坏的注释,其中包含空行,并且不能逐一浏览它们。
I haven't identified a command for editing rows in comments, and don't know where to start, so I don't have any code to show you guys. 我还没有确定用于编辑注释行的命令,也不知道从哪里开始,所以我没有任何代码可以向大家展示。 But I'm thinking in the line of:
但是我在考虑以下方面:
For Each comment In ActiveSheet.Comments
"REMOVE EMPTY ROWS" <-- What to put here?
Next comment
Hope that you can help me anyway! 希望您无论如何都能帮助我!
EDIT: All my empty lines are at the end of the comment like this: 编辑:我所有的空行都在注释的末尾,如下所示:
I found the answer. 我找到了答案。 It seems that it's not empty rows, it's just the size of the comment that was changed somehow.
似乎它不是空行,只是注释的大小有所更改。 So this code fixed it:
因此,此代码对其进行了修复:
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
Suppose your comment looks like this 假设您的评论如下所示
You could try this 你可以试试这个
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
to achieve 实现
Ok, after you've edited your question and changed the meaning with the provided details Ive come up with another code as a solution. 好的,在您编辑完问题并更改了所提供详细信息的含义之后,Ive提出了另一个代码作为解决方案。 Try
尝试
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.