If iLastY <> iY Then
With Range(Cells(2, 5), Cells([E65535].End(xlUp).Row, 5))
Set c = .Find(iY, LookIn:=xlValues)
If Not c Is Nothing Then
iKey = c.Row
Else
MsgBox ("儲存格 : C" + Right(Str(iNum), Len(Str(iNum)) - 1) + " 的 Y 值為 " + Str(iY) + " 找不到!")
Exit Sub
End If
End With
End If
For iI = Cells(iKey, 6) To Cells(iKey, 7)
If Cells(iNum, 2) <> iI Then
Cells(iAns, 9) = iI
Cells(iAns, 10) = iY
iAns = iAns + 1
Else
iNum = iNum + 1
End If
Next iI
iLastY = iY
iY = Cells(iSource, 3) '抓下一筆資料
iX = Cells(iSource, 2)
If iLastY <> iY Then ' Y 有新值
Cells(iComp, 7) = Cells(iSource - 1, 2) ' 代入上一個 Y 的 最大值 的X
iComp = iComp + 1
Cells(iComp, 5) = iY '代入新的 Y 與 最小值 的X
Cells(iComp, 6) = iX
iNum = iX
End If
Do While iNum <> iX ' 有缺項, 代入資料到缺項表格中, 直到不再有缺項
Cells(iAns, 9) = iNum
Cells(iAns, 10) = iY
iAns = iAns + 1
iNum = iNum + 1
Loop
iSource = iSource + 1
iNum = iNum + 1
iLastY = iY
Loop While iSource <= iDown ' 比較完畢
Cells(iComp, 7) = Cells(iSource - 1, 2) ' 帶入最後一個 最大值 的X
End Sub