2013-06-02 47 views
0

我在這裏遇到了一個非常具有挑戰性的問題。對我來說解決這個問題非常重要,以便我們部門能夠節省數百萬美元(真誠的幫助深受讚賞)。 其實我們有兩種不同的文本格式的「網格線數據」欄。例如GL 23.5-24/G。這裏23.5-24表示沿X軸的讀數,而G表示沿Y軸的磨削。所有這些數據都在一列中。有時數據不是單一值,而是數值的組合,例如GL 24-24.7/S-T,GL 25.3-25.5/S-T,有時類似於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)進行比較。比較應該以某種方式告訴我,比較網格是否落入主網格的UNDER(作爲子集)。 例如如果我的主網格線爲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 
+0

我知道他們是非常複雜的項目但我確定有很多專家可以真正管理它。我只需要總體指導,我會自己照顧這個項目。 Thnx –

+0

即使有人可以分享一些一般想法,我也會非常開心。我的想法是解析基於「,」值的數據,以便獲得不同的網格數據。然後主要是確定哪個值更高,即B> A等(僅基於字母)。畢竟,我可以使用一些比較技術來比較我的參考列表。 –

+0

夥計們,我回來了,並完全解決了這個問題。幾乎花了我一個月的時間才找到最終的解決方案。 –

回答

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 

因此,所有你需要做的就是把在一個單元格值和更大的矩形的值(你必須搜索)在另一個單元格,並使用上述功能。

相關問題