Excel公式查找最大/最小值

我有两列,一个X和Y列,它有数据点,当绘制(200 +数据点)时,它绘制了一个手绘方形。 我的职责是find(X,Y)四个angular点。 要做到这一点,我需要findX的最小值,最大的Y点来得到左上angular的点

我需要确定最大的X点和最大的Y值来查找左下angular的点等等。

但是,我不知道该怎么做,因为我可以findX / Y的最大值/最小值,但是我不会find4对angular。 有什么build议?

谢谢

如果两边总是平行于坐标系,则这些点是:

A: min(x), min(y) B: min(x), max(y) C: max(x), min(y) D: max(x), max(y) 

如果双方不平行,那么需要更聪明一点:

 A: min(x), the value of y where x is minimum B: the value of x where y is maximum, max(y) C: max(x), the value of y where x is maximum D: the value of x where y is minimum, min(y) 

这只适用于在最小或最大x处有一个且只有一个y,并且对于最小和最大x而言只有一个x。 代码需要完成所有这些。

假设坐标是在Sheet1中,x坐标在范围名称“x”中,y坐标在范围名称“y”中,下面的代码应该返回angular坐标:

 Option Explicit Sub addresses() Dim wks As Worksheet Dim sXMinAddress As String, sXMaxAddress As String Dim sXMinAddressY As String, sXMaxAddressY As String Dim xMin As Double, xMax As Double Dim xMinY As Double, xMaxY As Double Dim sYMinAddress As String, sYMaxAddress As String Dim sYMinAddressX As String, sYMaxAddressX As String Dim yMin As Double, yMax As Double Dim yMinX As Double, yMaxX As Double Dim testAddress As String, i As Integer Set wks = Worksheets("Sheet1") sXMaxAddress = wks.Range("x").Cells(1, 1).Address sXMinAddress = wks.Range("x").Cells(1, 1).Address sXMaxAddressY = wks.Range(sXMaxAddress).Offset(0, 1).Address sXMinAddressY = wks.Range(sXMinAddress).Offset(0, 1).Address xMax = wks.Range(sXMaxAddress).Value xMin = wks.Range(sXMinAddress).Value sYMaxAddress = wks.Range("y").Cells(1, 2).Address sYMinAddress = wks.Range("y").Cells(1, 2).Address sYMaxAddressX = wks.Range(sYMaxAddress).Offset(0, -1).Address sYMinAddressX = wks.Range(sYMinAddress).Offset(0, -1).Address yMax = wks.Range(sYMaxAddress).Value yMin = wks.Range(sYMinAddress).Value For i = 2 To wks.Range("x").Count testAddress = wks.Range("x").Cells(i, 1).Address If wks.Range(testAddress).Value < xMin Then xMin = wks.Range(testAddress).Value sXMinAddress = testAddress sXMinAddressY = wks.Range(testAddress).Offset(0, 1).Address xMinY = wks.Range(sXMinAddressY).Value End If If wks.Range(testAddress).Value > xMax Then xMax = wks.Range(testAddress).Value sXMaxAddress = testAddress sXMaxAddressY = wks.Range(testAddress).Offset(0, 1).Address xMaxY = wks.Range(sXMaxAddressY).Value End If Next i For i = 2 To wks.Range("y").Count testAddress = wks.Range("y").Cells(i, 1).Address If wks.Range(testAddress).Value < yMin Then yMin = wks.Range(testAddress).Value sYMinAddress = testAddress sYMinAddressX = wks.Range(testAddress).Offset(0, -1).Address yMinX = wks.Range(sYMinAddressX).Value End If If wks.Range(testAddress).Value > yMax Then yMax = wks.Range(testAddress).Value sYMaxAddress = testAddress sYMaxAddressX = wks.Range(testAddress).Offset(0, -1).Address yMaxX = wks.Range(sYMaxAddressX).Value End If Next i Debug.Print "Vertices:" Debug.Print "A: " & xMin & ", " & xMinY Debug.Print "B: " & xMax & ", " & xMaxY Debug.Print "C: " & yMaxX & ", " & yMax Debug.Print "D: " & yMinX & ", " & yMin Debug.Print "Sheet addresses" Debug.Print "A: " & sXMinAddress & "," & sXMinAddressY Debug.Print "B: " & sYMaxAddressX & "," & sYMaxAddress Debug.Print "C: " & sXMaxAddress & "," & sXMaxAddressY Debug.Print "D: " & sYMinAddressX & "," & sYMinAddress End Sub