vba - 将 Iferror 函数添加到 VBA
问题描述
你如何在这段代码中注入 iferror 函数?
For d = 2 To lastrowx2
Worksheets("Educational Service Report").Cells(d, 16).Value = Application.WorksheetFunction.VLookup( _
Worksheets("Educational Service Report").Cells(d, 15).Value, _
Worksheets("Educational Service Report").Range("X:Y"), 2, 0)
Next
如果它是一个错误,我只想要一个空值单元格(d,16)。
解决方案
像下面这样的东西会为你做这件事,一个嵌套的应用程序函数:
For d = 2 To lastrowx2
Worksheets("Educational Service Report").Cells(d, 16).Value = Application.IfError( _
Application.VLookup(Worksheets("Educational Service Report").Cells(d, 15).Value, _
Worksheets("Educational Service Report").Range("X:Y"), 2, 0), "")
Next d
推荐阅读
- python - RTL Python 字符串的一致终端输出
- regex - 使用查询选择多个标题而不是列
- c# - Unity C#中的事件(委托)和继承问题
- angular - 角度单元测试 - 如何监视可观察的属性
- sql - 如何拥有一个包含多个可能内容的“发布”表?
- python - 如何用整数更新 tkinter 标签
- node.js - Google App Engine NodeJS 应用程序在 30 分钟后停止
- java - 从 Java8 迁移到 Java11 java.lang.IndexOutOfBoundsException
- assembly - 有没有办法再重复一次?
- javascript - 在异步函数中使用 props 变量