VBA Excel 2010,isError 函数

标签 vba excel

如果没有发现错误,我希望程序输出一条消息。

   Sub casesVsQueue()
                 Dim loop_counter As Integer
                 Dim colD_counter As Integer
                 loop_counter = 1
                 colD_counter = 2
      Do Until IsEmpty(Sheets("Sheet1").Range("A" & loop_counter).Value)
              If IsError(Sheets("Sheet1").Range("C" & loop_counter).Value) Then      
                    Sheets("Sheet1").Range("D" & colD_counter).Value = Sheets("Sheet1").Range("A" & loop_counter).Value
                    colD_counter = colD_counter + 1

             End If
             loop_counter = loop_counter + 1
      Loop
End Sub

最佳答案

在你的循环之后的最后,在你关闭你的子之前添加这个:

      Loop
    If colD_counter = 2 Then MsgBox "Everything is fine"
End Sub

基本上是因为colD_counter 'counts' 错误,如果它在你的循环中没有改变,保持 = 2,那么你有 msgbox 说没有错误出现。

您可以保持其余的 vb 不变。我刚刚试了一下,它似乎工作正常。

关于VBA Excel 2010,isError 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37666444/

相关文章:

vba - 如何强制用户在工作表中启用宏?

string - 使用 VBA,拆分字符串并将第一项仅设置为变量?

mysql - 在不单击每个单元格的情况下更改标准格式的数字 - Excel

excel - 将长字符串(>255 个字符)计算为数组

vba - 检查工作簿中的工作表是否有特定名称,如果有则更改

excel - 来自 2 列或更多列的 VBA 唯一值

使用 SSIS 将数据从电子表格加载到数据库时,Excel 源出现不同步问题

excel - 根据其他列值在列中显示下拉选项

excel - Excel 中的这个表达式是什么意思

vba - 是否有 VBA 命令导致此时开始调试?