2017-01-26 11 views
0

私は、複数レベルの部品表の直下にある重複参照指数を強調表示するマクロに取り組んでいます。マルチレベル品目の重複参照設計者を強調表示する方法

enter image description here

私のコードは以下の通りです:

'To identify duplicates RDs 
Sheet1.Columns(14).Copy (Sheet4.Cells(1, 1)) 

Sheet4.Select 
    Sheet4.Rows("1:1").Select 
    Selection.Copy 
    Selection.Insert shift:=xlDown 
    Cells.Select 
    Selection.AutoFilter 
    ActiveSheet.Range("$A$1:$A$10000").AutoFilter Field:=1, Criteria1:="=" 
    Cells.Select 
    Selection.Delete shift:=xlUp 
    Sheet4.Columns(1).Interior.ColorIndex = xlNone 


    Dim FromLine As Integer 
    Dim ToLine As Integer 
    Dim Count As Integer 
    Dim Leng As Integer 
    Dim RefTemp, RefTemp1, RefTemp2 As String 
    Dim Cha As String 
    Dim ReferenceNo As String 
    Dim PartNo As String 
    Dim Description As String 
    Dim Flag As Boolean 

    FromLine = 1 
    Cha = " " 
    While Cells(FromLine, 1) <> "" 
     Flag = True 
     ReferenceNo = LTrim(Cells(FromLine, 1)) 
     RefTemp = RTrim(ReferenceNo) 
     Leng = Len(RefTemp) 
     Cells(FromLine, 1) = RefTemp 
     Count = 1 
     While Count <= Leng And Flag 

      RefTemp1 = Left(ReferenceNo, 1) 
      If RefTemp1 <> " " And RefTemp1 <> "," Then 

       ReferenceNo = Right(ReferenceNo, Leng - Count) 

      Else 
       Cells(FromLine, 1) = Left(RefTemp, Count - 1) 
       Flag = False 
       RefTemp2 = Right(ReferenceNo, Leng - Count) 

       FromLine = FromLine + 1 
       Rows(FromLine).Select 
       Selection.Insert shift:=xlDown 
       Cells(FromLine, 1) = RefTemp2 

       FromLine = FromLine - 1 
      End If 
      Count = Count + 1 
     Wend 
     FromLine = FromLine + 1 

    Wend 


    Dim cel1 As Variant 
    Dim myrng1 As Range 
    Dim clr1 As Long 
    Set myrng1 = Sheet4.Range("A1:A" & Sheet4.Range("A65536").End(xlUp).Row) 
    myrng1.Interior.ColorIndex = xlNone 

    j = 1 

    For Each cel1 In myrng1 
     If Application.WorksheetFunction.CountIf(myrng1, cel1) > 1 Then 
      If WorksheetFunction.CountIf(Sheet4.Range("A1:A" & cel1.Row), cel1) = 1 Then 

       Sheet4.Cells(j, 2).Value = cel1 
       j = j + 1 

      Else 
       cel1.Interior.ColorIndex = myrng1.Cells(WorksheetFunction.Match(cel1.Value, myrng1, False), 1).Interior.ColorIndex 
      End If 
     End If 
    Next 


Dim lastrow4 As Long 
lastrow4 = Sheet4.Range("B" & Rows.Count).End(xlUp).Row 

For i = 1 To lastrow4 
    For j = 1 To lastrow 
     k1 = InStr(Sheet1.Cells(j, 14).Value, Sheet4.Cells(i, 2).Value) 
     len1 = Len(Sheet4.Cells(i, 2).Value) 

     If k1 > 0 Then 
      Sheet1.Cells(j, 14).Interior.ColorIndex = 28 
      Sheet1.Cells(j, 14).Characters(k1, len1).Font.ColorIndex = 3 
     End If 
    Next j 
Next i 
Sheet4.Rows("1:" & Rows.Count).Delete shift:=xlUp 


Sheet1.Select 

問題:

要件はすぐにトップレベルの下で重複し '参考デス' を強調することです。

上のスクリーンショット 'P2' & 'P3'は 'M1'の直下の子です(P2 & P3はレベル2、M1はレベル1です)。

したがって、列Nでは、文字Jが強調表示されます。合ってます。

しかし、P4はM2の子です。強調表示してはいけません。

助けてください。

私は以下のように上記の問題のためのソリューションを持っている

答えて

0

'To identify duplicates RDs 
Sheet1.Columns(14).Copy (Sheet4.Cells(1, 1)) 

Sheet4.Select 
    Sheet4.Rows("1:1").Select 
    Selection.Copy 
    Selection.Insert shift:=xlDown 
    Cells.Select 
    Selection.AutoFilter 
    ActiveSheet.Range("$A$1:$A$10000").AutoFilter Field:=1, Criteria1:="=" 
    Cells.Select 
    Selection.Delete shift:=xlUp 
    Sheet4.Columns(1).Interior.ColorIndex = xlNone 


    Dim FromLine As Integer 
    Dim ToLine As Integer 
    Dim Count As Integer 
    Dim Leng As Integer 
    Dim RefTemp, RefTemp1, RefTemp2 As String 
    Dim Cha As String 
    Dim ReferenceNo As String 
    Dim PartNo As String 
    Dim Description As String 
    Dim Flag As Boolean 

    FromLine = 1 
    Cha = " " 
    While Cells(FromLine, 1) <> "" 
     Flag = True 
     ReferenceNo = LTrim(Cells(FromLine, 1)) 
     RefTemp = RTrim(ReferenceNo) 
     Leng = Len(RefTemp) 
     Cells(FromLine, 1) = RefTemp 
     Count = 1 
     While Count <= Leng And Flag 

      RefTemp1 = Left(ReferenceNo, 1) 
      If RefTemp1 <> " " And RefTemp1 <> "," Then 

       ReferenceNo = Right(ReferenceNo, Leng - Count) 

      Else 
       Cells(FromLine, 1) = Left(RefTemp, Count - 1) 
       Flag = False 
       RefTemp2 = Right(ReferenceNo, Leng - Count) 
       'PartNo = Cells(FromLine, 2) 
       'Description = Cells(FromLine, 3) 
       FromLine = FromLine + 1 
       Rows(FromLine).Select 
       Selection.Insert shift:=xlDown 
       Cells(FromLine, 1) = RefTemp2 
       'Cells(FromLine, 2) = PartNo 
       'Cells(FromLine, 3) = Description 
       FromLine = FromLine - 1 
      End If 
      Count = Count + 1 
     Wend 
     FromLine = FromLine + 1 

    Wend 


    Dim cel1 As Variant 
    Dim myrng1 As Range 
    Dim clr1 As Long 
    Set myrng1 = Sheet4.Range("A1:A" & Sheet4.Range("A65536").End(xlUp).Row) 
    myrng1.Interior.ColorIndex = xlNone 

    j = 1 

    For Each cel1 In myrng1 
     If Application.WorksheetFunction.CountIf(myrng1, cel1) > 1 Then 
      If WorksheetFunction.CountIf(Sheet4.Range("A1:A" & cel1.Row), cel1) = 1 Then 
       'cel1.Interior.ColorIndex = 7 
       'cel1.Font.ColorIndex = 1 
       Sheet4.Cells(j, 2).Value = cel1 
       j = j + 1 

      Else 
       cel1.Interior.ColorIndex = myrng1.Cells(WorksheetFunction.Match(cel1.Value, myrng1, False), 1).Interior.ColorIndex 
      End If 
     End If 
    Next 


Dim lastrow4 As Long 
lastrow4 = Sheet4.Range("B" & Rows.Count).End(xlUp).Row 

Dim myarr() As String 

For i = 1 To lastrow4 
    For j = 1 To lastrow 

     myarr() = Split(Sheet1.Cells(j, 14).Value, ",") 

     k1 = 0 

     For y = LBound(myarr) To UBound(myarr) 
      If myarr(y) = Sheet4.Cells(i, 2).Value Then 
       k1 = 1 
      End If 
     Next y 


     'L1 = InStr(Sheet1.Cells(j, 14).Value, Sheet4.Cells(i, 2).Value) 
     len1 = Len(Sheet4.Cells(i, 2).Value) 



     If Not IsEmpty(Sheet4.Cells(i, 2)) Then 
      If k1 > 0 Then 
       Start = 1 

       Do 
       L1 = InStr(Start, Sheet1.Cells(j, 14).Value, Sheet4.Cells(i, 2).Value) 

       If L1 > 0 Then 
        Start = L1 + 1 
        Sheet1.Cells(j, 14).Interior.ColorIndex = 28 
        Sheet1.Cells(j, 14).Characters(L1, len1).Font.ColorIndex = 3 
       End If 
       Loop While L1 > 0 


      End If 
     End If 
    Next j 
Next i 
Sheet4.Rows("1:" & Rows.Count).Delete shift:=xlUp 


Sheet1.Select 
関連する問題