| 
    
     |  | 概ね、こんな形で元のコードと同じ様に出力しているみたいだけど 元のコードのロジックが何か変な気がします
 通常は、何々以上何々未満若しくは、何々を超え何々以下の様な形に成るのに
 何々以上何々以下に成っている為、最小値と最大値の行き先が変?
 
 Public Sub Test2()
 
 Dim i As Long
 Dim rngScope As Range
 Dim vntKeys As Variant
 Dim vntResult As Variant
 
 Set rngScope = Range(Cells(1, "A"), Cells(65536, "A").End(xlUp))
 vntKeys = Range(Cells(1, "B"), Cells(65536, "B").End(xlUp)).Value
 ReDim vntResult(1 To UBound(vntKeys, 1), 1 To 1)
 
 For i = 1 To UBound(vntKeys, 1)
 vntResult(i, 1) = Application.Match(vntKeys(i, 1), rngScope, 1)
 If IsError(vntResult(i, 1)) Then
 vntResult(i, 1) = 2
 Else
 If vntKeys(i, 1) <> rngScope(vntResult(i, 1)) Then
 If vntResult(i, 1) + 1 <= rngScope.Rows.Count Then
 vntResult(i, 1) = vntResult(i, 1) + 1
 End If
 End If
 End If
 Next i
 Set rngScope = Nothing
 
 Cells(1, "C").Resize(UBound(vntKeys, 1)).Value = vntResult
 
 End Sub
 
 
 |  |