0

我在这里遇到了一个非常具有挑战性的问题。解决这个问题对我来说非常重要,以便我们部门节省数百万美元(非常感谢真诚的帮助)。实际上,我们有两列不同的文本形式的“网格线数据”。例如 GL 23.5-24 / G。这里 23.5 - 24 代表沿 X 轴的读数,而 G 代表沿 Y 轴的磨削。所有这些数据都在一列中。有时数据不是单个值,而是值的组合,例如 GL 24-24.7 / ST、GL 25.3-25.5 / ST,有时就像 GL 27/H;27/H.5;26.5/J.5 和 GL26 .5-27.5/L。现在我在处理这些数据时遇到了两大挑战。首先是我必须将此基于文本的数据转换为某种有用且可直接理解的网格线数据,即 GL 24-24.7 / ST 应该像 24 - 24。7 在一个单元格中,S - T 在另一个单元格中,清楚地表明 24 - 24.7 沿 X 轴,反之亦然。在我这样做之后,我必须将此数据与具有相同类型数据的另一列进行比较,即 GL 24.5 / S.5。比较应该以某种方式告诉我比较的网格是否属于(作为子集)主网格。例如,如果我的主网格线为 23 - 25 / R - T 并且我的第二个网格是 24.5 / S,那么第二个网格肯定会落在第一个网格之下(或介于两者之间)。

因此,总体问题是在将文本数据分离到有用的网格中之后检查其他中的第一条网格线。我做了一些临时工作,只是为了解析整个字符串,但无法形成合理的算法来进一步进行。

这是我当前解析数据的代码。

Dim strAll() As String
Dim strSNO() As String, Meesam() As String
Dim lastRow As Integer, i As Integer, newRng As Range, cnt As Integer, x As String
Dim a As Integer

With ThisWorkbook.Sheets("Data")
 lastRow = .Range("A7000").End(xlUp).Row
 ReDim strAll(lastRow)
 Set newRng = .Range("A1:A" & lastRow)
End With

For cnt = LBound(strAll()) To UBound(strAll())
    strAll(cnt) = newRng.Cells(cnt + 1, 1).Value
Next

Do While i < UBound(strAll)

If (InStr(1, strAll(i), "Element", vbTextCompare) > 0) Then
    i = i + 2
    Do Until InStr(1, strAll(50), "+GL", vbTextCompare) > 0 'Loop until line includes "+"
        Meesam = SplitMultiDelims(strAll(i), "/")
        a = 0
        For a = LBound(Meesam) To UBound(Meesam)
            newRng.Offset(i, a) = Meesam(a)
        Next
        i = i + 1
    Loop
End If
i = i + 1
Loop
4

1 回答 1

0
Function IsInside(Area As String, Rectangle As String) As Boolean

Dim Parts() As String
Dim Line1 As String, Line2 As String, Lx1 As Single, Ly1 As Single, Lx2 As String, Ly2 As String
Dim Rect1 As String, Rect2 As String, Rx1 As Single, Ry1 As Single, Rx2 As String, Ry2 As String

On Error Resume Next

Parts = Split(Replace(Area, " ", ""), "/")
Line1 = Parts(0)
Line2 = Parts(1)

If InStr(1, Line1, "-", vbTextCompare) > 0 Then
 Parts = Split(Line1, "-")
 Lx1 = Parts(0)
 Ly1 = Parts(1)
Else
Lx1 = Line1
Ly1 = "0"
End If

If InStr(1, Line2, "-", vbTextCompare) > 0 Then
 Parts = Split(Line2, "-")
 Lx2 = Parts(0)
 Ly2 = Parts(1)
Else
Lx2 = Line2
Ly2 = 0
End If

Parts = Split(Replace(Rectangle, " ", ""), "/")
Rect1 = Parts(0)
Rect2 = Parts(1)

If InStr(1, Rect1, "-", vbTextCompare) > 0 Then
 Parts = Split(Rect1, "-")
 Rx1 = Parts(0)
 Ry1 = Parts(1)
Else
 Rx1 = Rect1
 Ry1 = 0
End If

If InStr(1, Rect2, "-", vbTextCompare) > 0 Then
 Parts = Split(Rect2, "-")
 Rx2 = Parts(0)
 Ry2 = Parts(1)
Else
 Rx2 = Rect2
 Ry2 = 0
End If

If Lx1 > 0 And Ly1 > 0 And Lx2 > 0 And Ly2 > 0 And Rx1 > 0 And Ry1 > 0 And Rx2 > 0 And Ry2 > 0 Then
 IsInside = Lx1 >= Rx1 And Lx1 <= Ry1 And Lx2 >= Rx2 And Lx2 <= Ry2
ElseIf Lx1 > 0 And Ly1 = 0 And Lx2 > 0 And Ly2 > 0 And Rx1 > 0 And Ry1 > 0 And Rx2 > 0 And Ry2 > 0 Then
 IsInside = Lx1 >= Rx1 And Lx1 <= Ry1 And Lx2 >= Rx2 And Ly2 <= Ry2
ElseIf Lx1 > 0 And Ly1 = 0 And Lx2 > 0 And Ly2 = 0 And Rx1 > 0 And Ry1 > 0 And Rx2 > 0 And Ry2 > 0 Then
 IsInside = Lx1 >= Rx1 And Lx1 <= Ry1 And Lx2 >= Rx2 And Lx2 <= Ry2
ElseIf Lx1 > 0 And Ly1 > 0 And Lx2 > 0 And Ly2 > 0 And Rx1 > 0 And Ry1 = 0 And Rx2 > 0 And Ry2 > 0 Then
 IsInside = 0
ElseIf Lx1 > 0 And Ly1 = 0 And Lx2 > 0 And Ly2 > 0 And Rx1 > 0 And Ry1 = 0 And Rx2 > 0 And Ry2 > 0 Then
 IsInside = Lx1 = Rx1 And Lx2 >= Rx2 And Ly2 <= Ry2
ElseIf Lx1 > 0 And Ly1 = 0 And Lx2 > 0 And Ly2 = 0 And Rx1 > 0 And Ry1 = 0 And Rx2 > 0 And Ry2 > 0 Then
 IsInside = Lx1 = Rx1 And Lx2 >= Rx2 And Lx2 <= Ry2
ElseIf Lx1 > 0 And Ly1 > 0 And Lx2 > 0 And Ly2 > 0 And Rx1 > 0 And Ry1 = 0 And Rx2 > 0 And Ry2 = 0 Then
 IsInside = 0
ElseIf Lx1 > 0 And Ly1 = 0 And Lx2 > 0 And Ly2 > 0 And Rx1 > 0 And Ry1 = 0 And Rx2 > 0 And Ry2 = 0 Then
 IsInside = 0
ElseIf Lx1 > 0 And Ly1 = 0 And Lx2 > 0 And Ly2 = 0 And Rx1 > 0 And Ry1 = 0 And Rx2 > 0 And Ry2 = 0 Then
 IsInside = 0
ElseIf Lx1 > 0 And Ly1 > 0 And Lx2 > 0 And Ly2 > 0 And Rx1 > 0 And Ry1 > 0 And Rx2 > 0 And Ry2 = 0 Then
 IsInside = 0
ElseIf Lx1 > 0 And Ly1 = 0 And Lx2 > 0 And Ly2 > 0 And Rx1 > 0 And Ry1 > 0 And Rx2 > 0 And Ry2 = 0 Then
 IsInside = 0
ElseIf Lx1 > 0 And Ly1 = 0 And Lx2 > 0 And Ly2 = 0 And Rx1 > 0 And Ry1 > 0 And Rx2 > 0 And Ry2 = 0 Then
 IsInside = 0
Else
End If

End Function

因此,您所要做的就是将网格值放在一个单元格中,将较大矩形的值(您必须在其中搜索)放在另一个单元格中,然后使用上述功能。

于 2013-07-09T11:54:18.163 回答