簡體   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