【问题标题】:Compile error in Excel VBAExcel VBA中的编译错误
【发布时间】:2015-03-27 02:56:25
【问题描述】:

我开发了 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

【问题讨论】:

    标签: vba excel


    【解决方案1】:

    你的失踪和End If

    但你也有Do ... Loop While

    当它看起来应该适合你的情况时

    Do While
    ....
    Loop
    

    Do Until
    ...
    Loop
    

    【讨论】:

      【解决方案2】:

      请在您的代码中添加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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-10-28
        • 2013-06-19
        • 2014-03-11
        • 2018-02-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-09-11
        相关资源
        最近更新 更多