VBAでindexとmatch関数の組み合わせを再現したい。 添付のようにVBAでindexとmatch関数の組み合わせを再現することは 可能でしょうか。
VBAでindexとmatch関数の組み合わせを再現したい。 添付のようにVBAでindexとmatch関数の組み合わせを再現することは 可能でしょうか。
Visual Basic | Excel・90閲覧・50
ベストアンサー
IndexとMatchを使うという「手段」にこだわりがあるのなら既出の通りですが、「結果」の方が重視ならばVBAではFind関数がありますので、そちらで行と列を検索するのも手です。 Sub Sample() Dim fnd As Range, buf As Range Dim x As Long, y As Long, i As Long For i = 3 To Cells(Rows.Count, "K").End(xlUp).Row Set buf = Cells(i, "K") Set fnd = Range("C3:F3").Find(buf.Value, LookAt:=xlWhole) If fnd Is Nothing Then Cells(i, "M").Value = "[ERR]日付無し" Else x = fnd.Column End If Set buf = Cells(i, "L") Set fnd = Range("B4:B6").Find(buf.Value, LookAt:=xlWhole) If fnd Is Nothing Then Cells(i, "M").Value = "[ERR]項目無し" Else y = fnd.Row End If If Cells(i, "M").Value = "" Then Cells(i, "M").Value = Cells(y, x).Value Next i End Sub
質問者からのお礼コメント
ありがとうございます。教えて頂いた内容で作成してます。
お礼日時:5/29 16:13