anudach7

wxcel

Aug 15th, 2024 (edited)
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VBScript 11.31 KB | Source Code | 0 0
  1. Sub NPIstage()
  2.     Application.DisplayAlerts = False
  3.     Application.Calculation = xlManual
  4.     Application.EnableEvents = False
  5.    
  6.     Dim AB As String
  7.     Dim A, B, C As Worksheet
  8.     Dim N1, N2, N3, N4, N5, N6, S1, S2, S3, CP1, CR1, PR1, CC1, PC1, CR2, PR2, CC2, PC2, cr3, fc As Range
  9.     Dim R1, i, i1, i2, i3, i4, MR, lr, nr, C1, C2, C3, C4, C5 As Long
  10.     Dim dict As Object
  11.     Dim v As Variant
  12.     Dim ts As Long
  13.     Dim cs As Long
  14.    
  15.  
  16.    
  17.     Call RunSQLQuery
  18.    
  19.     AB = ThisWorkbook.Name
  20.  
  21.     Set A = Workbooks(AB).Sheets("KIOXIA BOMs Format")
  22.     Set B = Workbooks(AB).Sheets("NPI Operation Check")
  23.     Set C = Workbooks(AB).Sheets("84KIC")
  24.    
  25.     C1 = 7
  26.     C2 = 4
  27.     C3 = 5
  28.     C4 = 6
  29.     C5 = 8
  30.     MR = 500
  31.    
  32.     ts = 9
  33.     cs = 0
  34.     B.Cells(1, 3).Value = "Progress: 0%"
  35.  
  36.    
  37.    
  38.     With B.Range("B3:B5").Interior
  39.     .Color = vbYellow
  40.     End With
  41.     cs = cs + 1
  42.     B.Cells(1, 3).Value = "Progress: " & (cs / ts) * 100 & "%"
  43.  
  44.    
  45.    
  46.    
  47.     B.Rows("7:70000").Delete
  48.  
  49.     Set N1 = A.Rows("1:99").Find("*Maker*Product*Number")
  50.     If N1 Is Nothing Then
  51.         Set N1 = A.Rows("1:99").Find("*Product*N")
  52.     End If
  53.  
  54.     If Not N1 Is Nothing Then
  55.         i = N1.row + 1
  56.         R1 = 7
  57.         Do While i <= A.Cells(A.Rows.Count, N1.Column).End(xlUp).row And R1 <= 7 + MR
  58.             B.Cells(R1, C1).Value = A.Cells(i, N1.Column).Value
  59.             R1 = R1 + 1
  60.             i = i + 1
  61.         Loop
  62.     End If
  63.  
  64.     cs = cs + 1
  65.     B.Cells(1, 3).Value = "Progress: " & (cs / ts) * 100 & "%"
  66.  
  67.  
  68.     Set N2 = A.Rows("1:99").Find("Parts Code")
  69.     If N2 Is Nothing Then
  70.         Set N2 = A.Cells.Find("G-Code")
  71.     End If
  72.  
  73.     If Not N2 Is Nothing Then
  74.         i1 = N2.row + 1
  75.         R1 = 7
  76.         Do While i1 <= A.Cells(A.Rows.Count, N2.Column).End(xlUp).row And R1 <= 7 + MR
  77.             B.Cells(R1, C2).Value = A.Cells(i1, N2.Column).Value
  78.             R1 = R1 + 1
  79.             i1 = i1 + 1
  80.         Loop
  81.     End If
  82.    
  83.     cs = cs + 1
  84.     B.Cells(1, 3).Value = "Progress: " & (cs / ts) * 100 & "%"
  85.    
  86.    
  87.     Set N3 = A.Rows("1:99").Find("P-Code")
  88.     If N3 Is Nothing Then
  89.         Set N3 = A.Rows("1:99").Find("P Code")
  90.     End If
  91.  
  92.     If Not N3 Is Nothing Then
  93.         i2 = N3.row + 1
  94.         R1 = 7
  95.         Do While i2 <= A.Cells(A.Rows.Count, N3.Column).End(xlUp).row And R1 <= 7 + MR
  96.             B.Cells(R1, C3).Value = A.Cells(i2, N3.Column).Value
  97.             R1 = R1 + 1
  98.             i2 = i2 + 1
  99.         Loop
  100.     End If
  101.  
  102.     cs = cs + 1
  103.     B.Cells(1, 3).Value = "Progress: " & (cs / ts) * 100 & "%"
  104.  
  105.  
  106.     Set N4 = A.Cells.Find("Func*Name")
  107.     If Not N4 Is Nothing Then
  108.         i3 = N4.row + 1
  109.         R1 = 7
  110.         Do While i3 <= A.Cells(A.Rows.Count, N4.Column).End(xlUp).row And R1 <= 7 + MR
  111.             B.Cells(R1, C4).Value = A.Cells(i3, N4.Column).Value
  112.             R1 = R1 + 1
  113.             i3 = i3 + 1
  114.         Loop
  115.     End If
  116.  
  117.     Set N5 = A.Rows("1:99").Find("Part No*")
  118.     If N5 Is Nothing Then
  119.         Set N5 = A.Rows("1:99").Find("Loca*", LookIn:=xlValues)
  120.         If Not N5 Is Nothing Then
  121.             Set N5 = A.Cells.Find("Part*Location")
  122.         End If
  123.     End If
  124.  
  125.     If Not N5 Is Nothing Then
  126.         i4 = N5.row + 1
  127.         R1 = 7
  128.         Do While i4 <= A.Cells(A.Rows.Count, N5.Column).End(xlUp).row And R1 <= 7 + MR
  129.             B.Cells(R1, C5).Value = A.Cells(i4, N5.Column).Value
  130.             R1 = R1 + 1
  131.             i4 = i4 + 1
  132.         Loop
  133.     End If
  134.    
  135.     cs = cs + 1
  136.     B.Cells(1, 3).Value = "Progress: " & (cs / ts) * 100 & "%"
  137.  
  138.     Dim strippedValue As String
  139.     Dim sortedValue As String
  140.  
  141.  
  142.     On Error Resume Next
  143.     Set dict = CreateObject("Scripting.Dictionary")
  144.     Set CR1 = B.Range("E7:E500").SpecialCells(xlCellTypeConstants)
  145.     Set CR2 = B.Range("G7:G500").SpecialCells(xlCellTypeConstants)
  146.     Set cr3 = B.Range("H7:H500").SpecialCells(xlCellTypeConstants)
  147.     Set PR1 = C.UsedRange.Columns("A:M").SpecialCells(xlCellTypeConstants)
  148.  
  149. If Not CR1 Is Nothing And Not PR1 Is Nothing Then
  150.     For Each cell In PR1
  151.         If Not dict.exists(cell.Value) Then
  152.             dict.Add cell.Value, 1
  153.         End If
  154.     Next
  155.    
  156.     For Each cell In CR1
  157.         If cell.Value Like "PM903347*" Or cell.Value Like "PM9S0002H01A" Or cell.Value Like "PM9M0001X*" Or cell.Value Like "PM9M0001W0*" Or cell.Value Like "PM9S0001X0*" Or cell.Value Like "PM9M0001Y01*" Or cell.Value Like "PM9M0001U*" Or cell.Value Like "PM9M0001V*" Or cell.Value Like "PM90359740*" Or cell.Value Like "PM9M0003*" Or cell.Value Like "PM9035975*" Or cell.Value Like "PM9M0001901*" Then
  158.             cell.Interior.Color = RGB(128, 128, 128)
  159.         ElseIf dict.exists(cell.Value) Then
  160.             cell.Interior.Color = Nothing
  161.         Else
  162.             cell.Interior.Color = vbRed
  163.         End If
  164.     Next
  165. End If
  166.  
  167.  
  168.  
  169.     For Each cell In PR1
  170.         strippedValue = Replace(cell.Value, ",", " ")
  171.         sortedValue = SortComponents(strippedValue)
  172.         'Debug.Print "PR1 value: " & cell.Value & " Sorted: " & sortedValue
  173.        If Not dict.exists(sortedValue) Then
  174.             dict.Add sortedValue, 1
  175.         End If
  176.     Next
  177.    
  178.     For Each cell In cr3
  179.         strippedValue = Replace(cell.Value, ",", " ")
  180.         sortedValue = SortComponents(strippedValue)
  181.         'Debug.Print "CR3 value: " & cell.Value & " Sorted: " & sortedValue
  182.        If Not dict1.exists(sortedValue) Then
  183.             dict1.Add sortedValue, 1
  184.         End If
  185.     Next
  186.    
  187.     For Each cell In cr3
  188.         strippedValue = Replace(cell.Value, ",", " ")
  189.         sortedValue = SortComponents(strippedValue)
  190.         If dict.exists(sortedValue) Then
  191.             cell.Interior.Color = vbWhite
  192.         Else
  193.             cell.Interior.Color = vbRed
  194.         End If
  195.     Next
  196.  
  197.  
  198.    If Not CR2 Is Nothing And Not PR1 Is Nothing Then
  199.         For Each cell In PR1
  200.             If Not dict.exists(cell.Value) Then
  201.                 dict.Add cell.Value, 1
  202.             End If
  203.         Next
  204.        
  205.         For Each cell In CR2
  206.             If cell.Value Like "8LY*" Or cell.Value Like "MCF*" Or cell.Value Like "MBA*" Or cell.Value Like "8V**" Or cell.Value Like "MVS*" Or cell.Value Like "LABEL-18X19" Or cell.Value Like "MCB0*" Then
  207.             cell.Interior.Color = RGB(128, 128, 128)
  208.             ElseIf dict.exists(cell.Value) Then
  209.                 cell.Interior.Color = Nothing
  210.             Else
  211.                 cell.Interior.Color = vbRed
  212.             End If
  213.         Next
  214.                
  215.         dict.RemoveAll
  216.     End If
  217.  
  218.     On Error GoTo 0
  219.     dict.RemoveAll
  220.    
  221.     cs = cs + 1
  222.     B.Cells(1, 3).Value = "Progress: " & (cs / ts) * 100 & "%"
  223.    
  224.    For Each cell In B.Range("G7:G" & B.Cells(B.Rows.Count, "G").End(xlUp).row)
  225.         rownumber = cell.row
  226.         If B.Cells(rownumber, "E").Interior.Color = vbRed Or _
  227.            B.Cells(rownumber, "G").Interior.Color = vbRed Or _
  228.            B.Cells(rownumber, "H").Interior.Color = vbRed Then
  229.                 B.Cells(rownumber, "I").Interior.Color = vbRed
  230.                 B.Cells(rownumber, "i").Value = "Not found in 84KIC"
  231.         ElseIf B.Cells(rownumber, "E").Interior.Color = vbWhite Or _
  232.            B.Cells(rownumber, "G").Interior.Color = vbGreen Or _
  233.            B.Cells(rownumber, "H").Interior.Color = vbGreen Then
  234.                 B.Cells(rownumber, "I").Interior.Color = vbWhite
  235.                 B.Cells(rownumber, "i").Value = "OK"
  236.         End If
  237.     Next
  238.          Set rgba = B.Range("J7:J" & B.Cells(B.Rows.Count, 7).End(xlUp).row)
  239.         rgba.Formula = "=IFERROR(IF(OR(K7=""TZ"", K7=""Kim"", K7=""Tani"", K7=""Austin"", K7=""Abhi"", K7=""Erik"", K7=""Joel"", K7=""Dominic"", K7=""Chris"", K7=""Palmmy"", K7=""Elf"", K7=""Por""), ""OK"", I7), """")"
  240.     For Each cell In B.Range("G7:G" & B.Cells(B.Rows.Count, "G").End(xlUp).row)
  241.         rownumber = cell.row
  242.         If B.Cells(rownumber, "J").Value = "Not found in 84KIC" Then
  243.                 B.Cells(rownumber, "J").Interior.Color = vbRed
  244.         End If
  245.    
  246.     Next
  247.    
  248.         Set N5 = A.Rows("1:99").Find("Part No*")
  249.     If N5 Is Nothing Then
  250.         Set N5 = A.Rows("1:99").Find("Loca*", LookIn:=xlValues)
  251.         If Not N5 Is Nothing Then
  252.             Set N5 = A.Cells.Find("Part*Location")
  253.         End If
  254.     End If
  255.  
  256.     If Not N5 Is Nothing Then
  257.         i4 = N5.row + 1
  258.         R1 = 7
  259.         Do While i4 <= A.Cells(A.Rows.Count, N5.Column).End(xlUp).row And R1 <= 7 + MR
  260.             B.Cells(R1, C5).Value = A.Cells(i4, N5.Column).Value
  261.             R1 = R1 + 1
  262.             i4 = i4 + 1
  263.         Loop
  264.     End If
  265.     cs = cs + 1
  266.     B.Cells(1, 3).Value = "Progress: " & (cs / ts) * 100 & "%"
  267.  
  268.     v = Array("RIBBON*", "Tray*", "*bag*", "Paper*", "*carton*", "*shipping*", "*tape*", "tenta*", "Thermal*")
  269.     lr = B.Cells(B.Rows.Count, 7).End(xlUp).row
  270.    
  271.     nr = lr + 5
  272.    
  273.      With B.Cells(nr - 1, 5)
  274.         .Value = "THESE BELOW YELLOW HIGHLIGHT COME OUT FROM 84KIC, PLEASE CHECK IT BY MANUALLY!!"
  275.         .Font.Bold = True
  276.         .Font.Underline = xlUnderlineStyleSingle
  277.         .Font.Color = RGB(0, 0, 255)
  278.         .Font.Size = 16
  279.         .Font.Italic = True
  280.     End With
  281.    
  282.     For Each Value In v
  283.         For Each cell In C.UsedRange
  284.             If UCase(cell.Value) Like UCase(Value) Then
  285.                 B.Cells(nr, 7).Value = cell.Value
  286.                 B.Cells(nr, 5).Value = C.Cells(cell.row, 7).Value
  287.                 B.Cells(nr, 6).Value = C.Cells(cell.row, 2).Value
  288.                 B.Cells(nr, 7).Interior.Color = RGB(255, 255, 0)
  289.                 B.Cells(nr, 6).Interior.Color = RGB(255, 255, 0)
  290.                 B.Cells(nr, 5).Interior.Color = RGB(255, 255, 0)
  291.  
  292.                 nr = nr + 1
  293.             End If
  294.         Next
  295.     Next
  296.     cs = cs + 1
  297.     B.Cells(1, 3).Value = "Progress: 100%"
  298.  
  299.     Application.DisplayAlerts = True
  300.     Application.Calculation = xlAutomatic
  301.           Application.EnableEvents = True
  302. End Sub
  303.  
  304. Function SortComponents(inputString As String) As String
  305.     Dim arr() As String
  306.     Dim i As Integer
  307.     Dim j As Integer
  308.     Dim temp As String
  309.    
  310.  
  311.     arr = Split(Replace(inputString, ",", " "), " ")
  312.    
  313.      For i = LBound(arr) To UBound(arr) - 1
  314.         For j = i + 1 To UBound(arr)
  315.             If CompareComponents(Trim(arr(i)), Trim(arr(j))) > 0 Then
  316.                 temp = arr(i)
  317.                 arr(i) = arr(j)
  318.                 arr(j) = temp
  319.             End If
  320.         Next j
  321.     Next i
  322.    
  323.      SortComponents = Join(arr, " ")
  324. End Function
  325.  
  326. Function CompareComponents(comp1 As String, comp2 As String) As Integer
  327.      Dim num1 As Double
  328.     Dim num2 As Double
  329.    
  330.     On Error Resume Next
  331.     num1 = CDbl(Replace(comp1, "C", ""))
  332.     num2 = CDbl(Replace(comp2, "C", ""))
  333.     On Error GoTo 0
  334.    
  335.     If num1 = num2 Then
  336.         CompareComponents = StrComp(comp1, comp2, vbTextCompare)
  337.     ElseIf IsNumeric(num1) And IsNumeric(num2) Then
  338.         If num1 < num2 Then
  339.             CompareComponents = -1
  340.         Else
  341.             CompareComponents = 1
  342.         End If
  343.     Else
  344.         CompareComponents = StrComp(comp1, comp2, vbTextCompare)
  345.     End If
  346.  
  347. End Function
  348.  
  349. Sub Cleardata()
  350.  
  351. Call C1
  352. Call C2
  353. Call C3
  354.  
  355. End Sub
  356.  
  357. Sub C1()
  358.  
  359. shData.Cells.Clear
  360.  
  361. End Sub
  362.  
  363. Sub C2()
  364.     Application.EnableEvents = False
  365.     npidata.Rows("7:70000").Delete
  366.         Application.EnableEvents = True
  367. End Sub
  368.  
  369. Sub C3()
  370.     Sheet1.Cells.Clear
  371.    
  372. End Sub
  373.  
  374.  
  375.  
Advertisement
Add Comment
Please, Sign In to add comment