
[英]How to remove #N/A that appears through out a worksheet? (VBA for excel Required)
[英]How to check if string appears in worksheet *twice* Excel VBA?
我试图检查某个字符串是否在给定的工作表上出现两次。 到目前为止,我只能检查字符串是否出现一次:
For Each curr In wb.Worksheets(1).UsedRange
If InStr(1, curr.Value, searchString) > 0 Then
MsgBox ("searchString appears once")
End If
Next
如何检查 UsedRange 以查看该值是否出现两次? 这需要是一个宏(到目前为止,我已经找到了执行此操作的公式)。
当您找到第一个匹配项时设置一个标志,然后检查是否设置了该标志:
Dim first As Boolean
For Each curr In wb.Worksheets(1).UsedRange
If InStr(1, curr.Value, searchString) > 0 Then
If first Then MsgBox ("searchString appears twice")
first = True
End If
Next
If WorksheetFunction.CountIf(Worksheets(1).UsedRange, "*" & searchString & "*") > 1 Then
MsgBox searchString & " appears more than once"
End If
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.