0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

検索はFind か、VLookup を使っていましたが、Match が最速らしいので練習しました。
YouTubeのメンタExcelさんの動画を参考にさせていただきました。

変数RをRange型で宣言するとエラーが出ましたが、Variantにしたら動きました。

Sub kensaku()

  Dim R As Variant
  Dim FindRow As Long
  
  R = Range("A1:A4").Value
  
  FindRow = Application.Match(Range("D2"), R, 0)
  Range("E2") = Cells(FindRow, 2)
  
End Sub

Match.png

D2セルに番号を入力して実行すると、E2セルに対応する品名が表示されます。
検索範囲が大量にあるときはFindやVLookupよりMatchが速いみたいです。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?