Excel VBA-在内部使用VlookUp是错误的 [英] Excel VBA - Use VlookUp Inside Is Error

查看:38
本文介绍了Excel VBA-在内部使用VlookUp是错误的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过一系列单元格进行vlookup,并根据它返回一个值或#N/A,我想对此进行一些操作.

I need to do a vlookup through a range of cells, and depending on it returning a value or a #N/A, I want to do some action on it.

我试图将vlookup放置在iserror函数中,但这没用.

I tried to place the vlookup inside the iserror function but that didn't work.

这是我接下来尝试的方法,但也没有用:

This is what i tried next but is also not working:

Set costCentreMapping = Workbooks.Open(Filename:="C:\mapping.xlsx")
Sheets("Sheet2").Activate
Dim CostCentreRange As Range
Set CostCentreRange = Range("A4:E2967")

    Set test1 = Application.WorksheetFunction.VLookup(appid, CostCentreRange, 2, False)

            If IsError(test1) Then 

                appid.Offset(columnoffset:=15) = "value1"

            End If

你建议我做什么?

谢谢

推荐答案

正如我在评论中所说:

Set costCentreMapping = Workbooks.Open(Filename:="C:\mapping.xlsx")

Dim CostCentreRange As Range
Set CostCentreRange = costCentreMapping.Sheets("Sheet2").Range("A4:E2967")

Dim test1 as variant 'the variable must be a variant to accept an error.
    test1 = Application.VLookup(appid, CostCentreRange, 2, False)

            If IsError(test1) Then 

                appid.Offset(columnoffset:=15) = "value1"

            End If

这篇关于Excel VBA-在内部使用VlookUp是错误的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆