| |
▼T.K さん:
眠いので、思考力が、最悪ですので間違っているかもしれませんが。
Sheet1がクラス内では『昇順』だとして。
Sub Sample()
Dim v As Variant
Dim i As Long
Dim f As Long
Dim t As Long
Dim myClass As String
Dim dic As Object
Dim w As Variant
Dim c As Range
Dim x As Long
v = Sheets("Sheet1").Range("A1").CurrentRegion.Value
Set dic = CreateObject("Scripting.Dictionary")
For i = LBound(v, 1) To UBound(v, 1)
myClass = v(i, 1)
If Not dic.exists(myClass) Then
dic(myClass) = Array(i, i)
End If
w = dic(myClass)
w(1) = i
dic(myClass) = w
Next
With Sheets("Sheet2")
For Each c In .Range("A2", .Range("A" & .Rows.Count).End(xlUp))
x = 0
myClass = c.Value
f = c.Offset(, 1).Value
t = c.Offset(, 2).Value
For i = dic(myClass)(0) To dic(myClass)(1)
If (f >= v(i, 2) And f < v(i, 3)) Or _
(f <= v(i, 2) And t >= v(i, 3)) Or _
(f >= v(i, 2) And t <= v(i, 3)) Or _
(t > v(i, 2) And t <= v(i, 3)) Then
x = i
Exit For
End If
Next
If x > 0 Then
c.Offset(, 3).Value = v(x, 4)
Else
c.Offset(, 3).Value = "ハズレ"
End If
Next
End With
End Sub
|
|