가장 가까운 낮은값 찾기 (엑셀)
높은값 찾기는 적당히 부등호 방향을 조정하면 됨.
Sub vlookup_down()
'가장 가까이 낮은거 찾기
x1 = Range("a2").Column
x2 = Range("g2").Column
y1 = Range("a2").Row
y2 = Range("g2").Row
Do While (Cells(y1, x1) And Cells(y2, x2))
If Cells(y1, x1) > Cells(y2, x2) Then y2 = y2 + 1
If Cells(y1, x1) < Cells(y2, x2) Then y1 = y1 + 1
If Cells(y1, x1) = Cells(y2, x2) Then
If Cells(y1, x1 + 1) < Cells(y2, x2 + 1) Then y1 = y1 + 1
If Cells(y1, x1 + 1) > Cells(y2, x2 + 1) Then
Cells(y1, x1 + 2) = Cells(y2, x2 + 1)
If Cells(y1, x1) = Cells(y2 + 1, x2) And Cells(y1, x1 + 1) >= Cells(y2 + 1, x2 + 1) And Cells(y1, x1 + 2) =< Cells(y2 + 1, x2 + 1) Then
y2 = y2 + 1
Else
y1 = y1 + 1
End If
End If
End If
Loop
End Sub