[英]VBA loop through comments with specialcells - multiple iterations
Referring to my previous question: Loop through comments 提到我的上一个问题: 通过评论循环
When I loop through the comments using specialcells, some iterations happen multiple times. 当我使用特殊单元格遍历注释时,某些迭代会多次发生。 Ie for the code below, some cells that contain a comment (
rngTemp.Value
) are modified up to three times (ie the number is added three times to the cell value): 例如,对于下面的代码,某些包含注释的单元格(
rngTemp.Value
)最多修改三次(即,将数字加到该单元格值的三倍):
On Error Resume Next
Set rngComment = myTemplate.Sheets("Seite 1").Range("B14:T35").SpecialCells(xlCellTypeComments)
On Error GoTo 0
If rngComment Is Nothing Then
'Do nothing
Else
i = 1
For Each rngTemp In rngComment
If rngTemp.Comment Is Nothing Then
'do nothing change the if then else
Else
MsgBox rngTemp.value
rngTemp.value = rngTemp.value & CStr(i)
rngTemp.Characters(Start:=Len(rngTemp.value), Length:=1).Font.Superscript = True
footnote = footnote & CStr(i) & ". " & rngTemp.Comment.Text & "; "
i = i + 1
End If
Next
footnotespage1 = footnote
End If
Do you know that error and know how to fix or work around it? 您是否知道该错误,并且知道如何解决或解决该错误?
Change the code to the below:- 将代码更改为以下代码:-
If rngTemp.Comment Is Nothing Then
'do nothing change the if then else
Else
If rngTemp.Characters(Start:=Len(rngTemp.value), Length:=1).Font.Superscript <> True Then
MsgBox rngTemp.value
rngTemp.value = rngTemp.value & CStr(i)
rngTemp.Characters(Start:=Len(rngTemp.value), Length:=1).Font.Superscript = True
footnote = footnote & CStr(i) & ". " & rngTemp.Comment.Text & "; "
i = i + 1
End If
End If
If it ends in a superscript already then won't do it at all. 如果它已经以上标结尾,那么将完全不做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.