简体   繁体   中英

Compile error in Excel VBA

I have developed VBA code to search the particular email type (for example .@gmail.com) in Excel. It will mark the next cell as a "TRUE" which is matched by condition.

I got compile error in do while loop

不做编译时间错误循环

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

Your missing and End If

but also you have Do ... Loop While

when it looks like it should be for your circumstances

Do While
....
Loop

or

Do Until
...
Loop

Please add a end if to your code.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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