簡體   English   中英

Excel VBA中的編譯錯誤

[英]Compile error in Excel VBA

我已經開發了VBA代碼以在Excel中搜索特定的電子郵件類型(例如。@ gmail.com)。 它將下一個單元格標記為“ TRUE”,並與條件匹配。

我在do while循環中遇到編譯錯誤

不做編譯時間錯誤循環

Dim c As Range
Dim SrchRng
Dim myarray As Variant
myarray = Array("@email.com","@gmail.com")

Set SrchRng = ActiveSheet.UsedRange
for each emailarray in myarray
    Do
        Set c = SrchRng.Find("emailarray", LookIn:=xlValues)
        If Not c Is Nothing Then 
           'c.EntireRow.Delete
             row_num = Split(c.Address(ColumnAbsolute:=False, RowAbsolute:=False), "A")
             Range("C" & row_num(1)).Value = "True"
    Loop While Not c Is Nothing

next emailarray

你的失蹤和End If

但是你也有Do ... Loop While

看起來應該適合您的情況

Do While
....
Loop

要么

Do Until
...
Loop

請在代碼end if加上end if

If Not c Is Nothing Then
    'c.EntireRow.Delete
    row_num = Split(c.Address(ColumnAbsolute:=False, RowAbsolute:=False), "A") 
    Range("C" & row_num(1)).Value = "True" 
End If

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM