单元格A1
具有框的左上角坐标,框的A2
右下角坐标,如何A3
以 csv 格式显示框的所有坐标?
前任:
Cell A1 = (24,20)
Cell A2 = (26,19)
如何获得这个?:
Cell A3 = (24,20),(25,20),(26,20),(24,19),(25,19),(26,19)
我正在使用 Excel 2011
单元格A1
具有框的左上角坐标,框的A2
右下角坐标,如何A3
以 csv 格式显示框的所有坐标?
前任:
Cell A1 = (24,20)
Cell A2 = (26,19)
如何获得这个?:
Cell A3 = (24,20),(25,20),(26,20),(24,19),(25,19),(26,19)
我正在使用 Excel 2011
这是你正在尝试的吗?(我希望我正确理解了您的问题。如果没有,请随时纠正我)
将此代码粘贴到模块中,然后调用=GetCord(A1,A2)
in 单元格A3
,如下面的屏幕截图所示。
Public Function GetCord(rng1 As Range, rng2 As Range) As String
Dim strTmp As String, strTmp1 As String, strTmp2 As String
Dim a As Long, b As Long, i As Long, j As Long, k As Long
strTmp1 = rng1.Value: strTmp2 = rng2.Value
strTmp1 = Trim(Replace(strTmp1, "(", ""))
strTmp1 = Trim(Replace(strTmp1, ")", ""))
strTmp2 = Trim(Replace(strTmp2, "(", ""))
strTmp2 = Trim(Replace(strTmp2, ")", ""))
i = Val(Split(strTmp1, ",")(0))
j = Val(Split(strTmp1, ",")(1))
k = Val(Split(strTmp2, ",")(0))
l = Val(Split(strTmp2, ",")(1))
For b = j To l Step -1
For a = i To k
strTmp = strTmp & "(" & a & "," & b & "),"
Next a
Next b
GetCord = Left(strTmp, Len(strTmp) - 1)
End Function
截屏
注意:上述功能是假设y
坐标按降序排列。为了满足所有情况,您必须在函数中包含该检查。