[ 初めての方へ | 一覧(最新更新順) | 全文検索 | 過去ログ ]
『ワークシート関数で戻り値がない場合の処理について』(oku)
MsgBox answer1
よろしくお願いいたします
1、
Dim answer1 as long
On error resume next
answer1 = Application.WorksheetFunction.VLookup(name, Range("name行変換"), 2, False)
on error goto 0
if answer1 > 0 Then
ある
else
ない
end if
あああ、VLookupでしたよね。 じゃぁ、1の方はなし。(Matchと同じにしてしまった。)12:52 追加
2、
Dim answer1 as Variant
answer1 = Application.VLookup(name, Range("name行変換"), 2, False)
if not iserror(answer1) Then
ある
else
ない
end if
BJ
衝突しましたが、そのまま・・・
Application.WorksheetFunction.VLookup を Application.VLookup と書くとエラーを返すのでIsErrorでチェックするか(test1)
事前にCountIf関数で存在をチェックするか(test2)
くらいが簡単ではないでしょうか
Sub test1()
Dim answer1 As Variant
Dim myName As String
myName = "test"
answer1 = Application.VLookup(myName, Range("name行変換"), 2, False)
If IsError(answer1) Then
MsgBox "エラー"
Else
MsgBox answer1
End If
End Sub
Sub test2()
Dim answer1 As Variant
Dim myName As String
Dim chk As Long
myName = "test"
chk = Application.WorksheetFunction.CountIf(Range("name行変換"), myName)
If chk = 0 Then
MsgBox "エラー"
Else
answer1 = Application.VLookup(myName, Range("name行変換"), 2, False)
MsgBox answer1
End If
End Sub
(momo)
[ 一覧(最新更新順) ]
YukiWiki 1.6.7 Copyright (C) 2000,2001 by Hiroshi Yuki.
Modified by kazu.