繁体   English   中英

用于搜索单元格范围以查看它是否包含空格的 Excel VBA 代码

[英]Excel VBA Code to search range of cells to see if it contains a space

我搜索了高低,但我在使用 vba 代码来搜索范围,即 A1:A1000,如果它找到一个包含空格的单元格,则弹出一个消息框。

谢谢

怎么样..

Set r = Range("A1:A1000").Find(What:=" ", LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False)
If r Is Nothing Then
' code to run if nothing found
Else
 MsgBox "Space found in cell " & r.Address
End If

编辑- 删除了After:参数,因为当超出搜索区域的单元格处于活动状态时,这会导致问题。

只是一个例子:

Dim cell As Range

Set cell = Range("A1:A1000").Find(What:=" ", After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False)

If cell Is Nothing Then
    Stop 'do something
Else
    Stop 'do something else
End If

更多信息: https : //msdn.microsoft.com/en-us/library/office/ff839746.aspx

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM