伊莉討論區

標題: 相對欄位迴圈判斷問題 [打印本頁]

作者: v03586    時間: 2016-1-20 02:02 AM     標題: 相對欄位迴圈判斷問題

本帖最後由 v03586 於 2016-1-20 02:04 AM 編輯

請問一下我有一個跑報表程式...遇到一個問題

Q1.我針對程式碼修改至我自己的程式報表(FMC), 發現欄位Substrate 與 B/D No 欄位 就是取 『-』 好像切得不是很乾淨 , 不知道是不是程式判斷有錯誤 (X與Y欄位) , 此欄位在ONHAND2HR_Ist_Flow 中是在<AD/AE欄位>
還有最後一欄一長串那個(Flow)<Z欄位>, 只要保留前面到字串中
『  SPC  』 或 『  SCL  』,後面都不要
跑巨集的時候能呈獻 『  QVS 』後就往下自動換列嗎,
範例:
WGD,FL0,WS0,UTI,VS0,QVS,
STB,PL0,DA0,SA0,EC0,DA1,RA2,EC1,PLM,WB0,PI0,QPI,RA3,CA0,EC2,SPC
[attach]112667280[/attach]
Q2.還有可以將匯入報表模式改成 Excel 打開後比對 (參考報表資料來源:ONHAND2HR_Ist_Flow)
          A2欄位有 ON HAND--PC_ONHAND2HR_1ST_FLOW 就等同匯入報表嗎?  
      意思就是只要打開程式EXCEL 與 參考資料來源EXCEL<
ONHAND2HR_Ist_Flow> 比對資料表Sheet1 A2欄有ON HAND--PC_ONHAND2HR_1ST_FLOW 字眼  就能執行程式目前是必須將檔案下載 , 與程式放在同一個資料夾, 才能執行程式

Q3.欄位線的劃置能全部細線條 , 依照B/D No 不同畫粗線條嗎? (執行結果excel那樣)
   目前好像不同的MO 畫粗線

請問大大能否新增幾樣功能嗎
1. 功能1
    1-1. 如果執行時間比對參考資料來源Date Time (C欄)超過24H 能幫我反黃色標示嗎?

           我記得可以設定儲存格格式化條件(但我設了沒有作用)
2. 功能2
   2-1. 程式中報表上CUSTNAME 欄位(V欄位)中如果有 CSP / L1 / L2 / 字串則整個刪除
   2-2. 保留 ENG / HQCSP / HQ-CSP / HQ-L1 / HQ-L2 / HQL1 / HQL2
   2-3. 然後移去ENG 移至ENG資料表, HQ CSP系列移至CSP資料表, HQ L1 / HQ L2 系列移至Other資料表
3. 功能3
    3-1. 報表參考資料(
ONHAND2HR_Ist_Flow)中的Q欄位QTY ,能比對 P欄位 STEP 帶入,
            程式中H欄~U欄位相對製程欄位嗎?   (如執行結果EXCEL) <重點功能>
4. 功能4
   4-1. 程式中,資料表FMC,前面有看見A欄位(PKG)與B欄位(MO) 已有合併儲存格, 發現後面有很多相同重複的 也可以合併嗎?
     4-1-1. V欄位(Custname)  W欄位(Device)  C欄位(Datetime) G欄位(MO QTY)   X欄位Substrate  Y欄位(B/D No)  Z欄位(Flow)



[attach]112667311[/attach]


作者: v03586    時間: 2016-1-22 01:57 AM

本帖最後由 v03586 於 2016-1-22 07:40 AM 編輯

已經將功能4問題解決...剩下求助[size=13.3333px]

更正功能3問題
3. 功能3
    3-1. 報表中的AA欄位QTY ,能比對 P欄位 STEP 帶入,H欄~U欄位相對製程欄位嗎?   
          EX: ( F9欄位=DB) AA數字70 ,  則帶入對應欄為 U欄(DB) U9顯示AA欄數字70
[attach]112690115[/attach]
  1. Dim UType%
  2. Sub 新報表_匯入()
  3. Dim xFile$, X As New Application, xB As Workbook, xS As Worksheet
  4. Dim RepSht As Worksheet, xR As Range, xLab As Range, xAddress$
  5. Set RepSht = Sheets("FMC")

  6. RepSht.UsedRange.EntireRow.Delete

  7. xFile = [comply!C3]
  8. If xFile = "" Then MsgBox "報表檔名稱未輸入! ": Exit Sub
  9. xFile = ThisWorkbook.Path & "\" & xFile & ".xls"
  10. If Dir(xFile) = "" Then MsgBox "找不到報表檔! ": Exit Sub
  11. Set xB = X.Workbooks.Open(xFile, ReadOnly:=True)
  12. Set xS = xB.Sheets(1)
  13. R = xS.Cells(Rows.Count, 1).End(xlUp).Row + 5
  14. Application.ScreenUpdating = False

  15. With RepSht
  16.      .Range("A1:A" & R) = xS.Range("AJ1:AJ" & R).Value  'pkg
  17.      .Range("B1:B" & R) = xS.Range("B1:B" & R).Value 'MO
  18.      
  19.      .Range("C1:C" & R).NumberFormatLocal = "@"   'Date time
  20.      .Range("C1:C" & R) = xS.Range("L1:L" & R).Value   'Date time
  21.      
  22.      .Range("D1:D" & R) = xS.Range("A1:A" & R).Value 'LOTID

  23.      .Range("E1:E" & R) = xS.Range("D1:D" & R).Value  'DIE TYPE
  24.      .Range("F1:F" & R) = xS.Range("P1:P" & R).Value   'STEP
  25.      .Range("G1:G" & R) = xS.Range("M1:M" & R).Value  ' MO QTY
  26.      .Range("AA1:AA" & R) = xS.Range("Q1:Q" & R).Value   '  QTY
  27.      .Range("H8").Value = "TBG1"
  28.      .Range("I8").Value = "PGH1"
  29.      .Range("J8").Value = "SLS1"
  30.      .Range("K8").Value = "WG"
  31.      .Range("L8").Value = "DE01"
  32.      .Range("M8").Value = "WM01"
  33.      .Range("N8").Value = "FL01"
  34.      .Range("O8").Value = "LWS1"
  35.      .Range("P8").Value = "WS01"
  36.      .Range("Q8").Value = "UTI1"
  37.      .Range("R8").Value = "VS01"
  38.      .Range("S8").Value = "QVS1"
  39.      .Range("T8").Value = "RQVS1"
  40.      .Range("U8").Value = "DB"
  41.      .Range("V1:W" & R) = xS.Range("E1:F" & R).Value  'CUST DEVICE
  42.      
  43.      
  44.      
  45.      .Range("X1:X" & R) = xS.Range("AD1:AD" & R).Value  'Substrate
  46.      .Range("Y1:Y" & R) = xS.Range("AE1:AE" & R).Value  'B/D No
  47.      .Range("Z1:Z" & R) = xS.Range("AQ1:AQ" & R).Value  'flow
  48.      
  49.      .Range("A8").Value = "PKG"
  50.      .Range("A7").Value = ""
  51.      .Range("X8").Value = "Substrate"
  52.      .Range("X7").Value = ""
  53.      .Range("Y8").Value = "B/D No."
  54.      .Range("Y7").Value = ""
  55.      .Range("D2").Value = ""
  56.      
  57.      .Range("A1").Value = "1ST Flow On Hand Report"
  58.      .Range("A2").Value = Now()
  59. '     For g = 3500 To 8 Step -1
  60. '        If .Cells(g, "V") Like "*CSP*" Or .Cells(g, "V") Like "*L1*" Or .Cells(g, "V") Like "*L2*" _
  61. '           Or .Cells(g, "V") Like "*ENG*" Or .Cells(g, "A") Like "LQFP*" Or .Cells(g, "A") Like "PLCC*" _
  62. '           Or .Cells(g, "A") Like "SOP*" Or .Cells(g, "A") Like "SSOP*" Or .Cells(g, "A") Like "TSOP*" _
  63. '           Or .Cells(g, "A") Like "TSSOP*" Then
  64. '            .Rows(g).Delete
  65. '        End If
  66. '     Next

  67. End With


  68. xB.Close 0


  69. Dim RR&, xArea As Range, xRR As Range, xH As Range, T, TT, XX
  70. RR = [FMC!A65536].End(xlUp).Row: If RR < 9 Then Exit Sub
  71. Set xArea = Sheets("FMC").Range("A9:A" & R)
  72. For Each xRR In xArea
  73.     T = xRR(1, 25): xRR(1, 25) = Mid(T, InStr(T, "-") + 1)
  74.     xRR(1, 24) = Right(xRR(1, 24), 9)
  75.       
  76.     T = xRR(1, 5):  T = Left(T, 2) & "-" & Mid(T, 24, 1) & "-" & Mid(T, 23, 4)
  77. '    TT = Application.VLookup(T, [Flow!A:B], 2, 0)
  78. '    If Not IsError(TT) Then xRR(1, 5) = TT Else xRR(1, 5).Font.Color = vbRed
  79.       
  80.     T = xRR(1, 11)
  81.     T = Mid(T & ",QVS", InStr(T, "QVS") + 4) '取 QVS 以後字串
  82.     For Each TT In Array("SPC", "SCL")
  83.         XX = InStr(T, TT): If XX > 0 Then xRR(1, 11) = Left(T, X + 2): Exit For
  84.     Next
  85. Next


  86. xArea.Resize(, 26).Sort Key1:=xArea(1, 1), Order1:=xlAscending, _
  87.                        Key2:=xArea(1, 25), Order2:=xlAscending, Header:=xlNo
  88.                         
  89. Application.DisplayAlerts = False
  90. For Each xRR In xArea
  91.     If xRR & xRR(1, 2) <> xRR(0) & xRR(0, 2) Then Set xH = xRR
  92.     If xRR & xRR(1, 2) <> xRR(2) & xRR(2, 2) Then
  93.       Range(xH, xRR).Merge: Range(xH(1, 2), xRR(1, 2)).Merge
  94.       Range(xH, xRR).Merge: Range(xH(1, 3), xRR(1, 3)).Merge
  95.       Range(xH, xRR).Merge: Range(xH(1, 7), xRR(1, 7)).Merge
  96.       Range(xH, xRR).Merge: Range(xH(1, 22), xRR(1, 22)).Merge
  97.       Range(xH, xRR).Merge: Range(xH(1, 23), xRR(1, 23)).Merge
  98.       Range(xH, xRR).Merge: Range(xH(1, 24), xRR(1, 24)).Merge
  99.       Range(xH, xRR).Merge: Range(xH(1, 25), xRR(1, 25)).Merge
  100.       Range(xH, xRR).Merge: Range(xH(1, 26), xRR(1, 26)).Merge
  101.       Range(xH, xRR(1, 26)).Borders.LineStyle = 1
  102.       For i = 7 To 10
  103.           Range(xH, xRR(1, 26)).Borders(i).Weight = xlMedium
  104.       Next i
  105.     End If
  106. Next
  107. With RepSht
  108.     Sheets("FMC").Select
  109.     Cells.Select
  110.     Selection.Font.Size = 14
  111.     With Selection.Font
  112.         .Name = "Arial"
  113.         .Size = 14
  114.         .Strikethrough = False
  115.         .Superscript = False
  116.         .Subscript = False
  117.         .OutlineFont = False
  118.         .Shadow = False
  119.         .Underline = xlUnderlineStyleNone
  120.         .ThemeColor = xlThemeColorLight1
  121.         .TintAndShade = 0
  122.         .ThemeFont = xlThemeFontNone
  123.     End With
  124.     Range("A8:Z8").Select
  125.     With Selection.Interior
  126.         .Pattern = xlSolid
  127.         .PatternColorIndex = xlAutomatic
  128.         .Color = 255
  129.         .TintAndShade = 0
  130.         .PatternTintAndShade = 0
  131.     End With
  132.     With Selection.Font
  133.         .ThemeColor = xlThemeColorDark1
  134.         .TintAndShade = 0
  135.     End With
  136. End With
  137.     Range("A8").Select
  138.     ActiveWindow.Zoom = 63

  139. Call 調整
  140.    
  141. End Sub

  142. Sub 報表_清除()
  143. Sheets("FMC").UsedRange.EntireRow.Delete
  144. End Sub



  145. Sub 調整()
  146. '
  147. ' 巨集1 巨集
  148. '
  149. Dim RepSht As Worksheet
  150. Set RepSht = Sheets("FMC")
  151. '
  152. With RepSht
  153.     Columns("A:A").Select
  154.     Selection.ColumnWidth = 30
  155.     Columns("B:B").Select
  156.     Selection.ColumnWidth = 11.63
  157.     Columns("C:C").Select
  158.     Selection.ColumnWidth = 16
  159.     Columns("D:D").Select
  160.     Selection.ColumnWidth = 20.88
  161.     Columns("E:E").Select
  162.     Selection.ColumnWidth = 8.25
  163.     Columns("F:F").Select
  164.     Selection.ColumnWidth = 9.25
  165.     Columns("G:G").Select
  166.     Selection.ColumnWidth = 10
  167.     Selection.NumberFormatLocal = "#,##0_ "
  168.     Columns("H:U").Select
  169.     Selection.ColumnWidth = 8.63
  170.     Columns("V:V").Select
  171.     Selection.ColumnWidth = 40.38
  172.     ActiveWindow.SmallScroll ToRight:=11
  173.     Columns("W:W").Select
  174.     Selection.ColumnWidth = 59.75
  175.     Columns("X:X").Select
  176.     Selection.ColumnWidth = 15.5
  177.     Columns("Y:Y").Select
  178.     Selection.ColumnWidth = 10.5
  179.     ActiveWindow.SmallScroll ToRight:=4
  180.     Columns("Z:Z").Select
  181.     Selection.ColumnWidth = 93.38
  182.     Range("A7").Select
  183. End With

  184. End Sub
複製代碼




作者: v03586    時間: 2016-1-23 02:06 AM

功能3我能想到的呈現方式就是
如果F欄未 [STEP] = TBG1 則就從AA欄位剪下貼上, 請問如何寫成多判斷
  1. For h = 9 To 3500
  2.         If .Cells(h, "F") = "TBG1" Then
  3.             .Cells(h, "AA").Select
  4.             Selection.Cut
  5.             .Cells(h, "H").Select
  6.             ActiveSheet.Paste
  7.         End If
  8.     next
複製代碼
我在下面在新增一個if  就跑不出來了
還有什麼辦法呢?或者如何修改?
  1. For h = 9 To 3500
  2.         If .Cells(h, "F") = "TBG1" Then
  3.             .Cells(h, "AA").Select
  4.             Selection.Cut
  5.             .Cells(h, "H").Select
  6.             ActiveSheet.Paste
  7.         End If
  8.         If .Cells(h, "F") = "PGH1" Then
  9.             .Cells(h, "AA").Select
  10.             Selection.Cut
  11.             .Cells(h, "I").Select
  12.             ActiveSheet.Paste
  13.         End If
  14.       Next
複製代碼

作者: rr09192084    時間: 2016-1-23 09:11 AM

  1. With ActiveSheet
  2.   For h = 9 To 3500
  3.    Select Case .Cells(h, "A").Value
  4.     Case "TBG1"
  5.      .Cells(h, "AA").Select
  6.      Selection.Cut
  7.      .Cells(h, "H").Select
  8.      ActiveSheet.Paste
  9.     Case "PGH1"
  10.      .Cells(h, "AA").Select
  11.      Selection.Cut
  12.      .Cells(h, "I").Select
  13.      ActiveSheet.Paste
  14.    End Select
  15.   Next
  16. End With
複製代碼
多重條件要確定是多選一,則用Select Case語法會比較適當。
作者: v03586    時間: 2016-1-23 11:41 AM

本帖最後由 v03586 於 2016-1-23 12:10 PM 編輯
rr09192084 發表於 2016-1-23 09:11 AM
多重條件要確定是多選一,則用Select Case語法會比較適當。

感謝大大指教

我寫完出現一個錯誤

[attach]112705755[/attach]

我的程式碼如下

  1. Dim RepSht As Worksheet, xR As Range, xLab As Range, xAddress$
  2. Set RepSht = Sheets("FMC")
  3. With RepSht
  4.      
  5.   For h = 9 To 3500
  6.    Select Case .Cells(h, "F").Value
  7.     Case "TBG1"
  8.      .Cells(h, "AA").Select
  9.      Selection.Cut
  10.      .Cells(h, "H").Select
  11.      ActiveSheet.Paste
  12.     Case "PGH1"
  13.      .Cells(h, "AA").Select
  14.      Selection.Cut
  15.      .Cells(h, "I").Select
  16.      ActiveSheet.Paste
  17.     Case "SLS1"
  18.      .Cells(h, "AA").Select
  19.      Selection.Cut
  20.      .Cells(h, "J").Select
  21.      ActiveSheet.Paste
  22.     Case "DE01"
  23.      .Cells(h, "AA").Select
  24.      Selection.Cut
  25.      .Cells(h, "L").Select
  26.      ActiveSheet.Paste
  27.     Case "WM01"
  28.      .Cells(h, "AA").Select
  29.      Selection.Cut
  30.      .Cells(h, "L").Select
  31.      ActiveSheet.Paste
  32.     Case "FL01"
  33.      .Cells(h, "AA").Select
  34.      Selection.Cut
  35.      .Cells(h, "N").Select
  36.      ActiveSheet.Paste
  37.     Case "LWS1"
  38.      .Cells(h, "AA").Select
  39.      Selection.Cut
  40.      .Cells(h, "O").Select
  41.      ActiveSheet.Paste
  42.     Case "WS01"
  43.      .Cells(h, "AA").Select
  44.      Selection.Cut
  45.      .Cells(h, "P").Select
  46.      ActiveSheet.Paste
  47.     Case "UTI1"
  48.      .Cells(h, "AA").Select
  49.      Selection.Cut
  50.      .Cells(h, "Q").Select
  51.      ActiveSheet.Paste
  52.     Case "VS01"
  53.      .Cells(h, "AA").Select
  54.      Selection.Cut
  55.      .Cells(h, "R").Select
  56.      ActiveSheet.Paste
  57.     Case "QVS1"
  58.      .Cells(h, "AA").Select
  59.      Selection.Cut
  60.      .Cells(h, "S").Select
  61.      ActiveSheet.Paste
  62.     Case "RQVS1"
  63.      .Cells(h, "AA").Select
  64.      Selection.Cut
  65.      .Cells(h, "T").Select
  66.      ActiveSheet.Paste
  67.     Case "DB"
  68.      .Cells(h, "AA").Select
  69.      Selection.Cut
  70.      .Cells(h, "U").Select
  71.      ActiveSheet.Paste
  72.    End Select
  73.   Next
  74.     For e = 9 To 3500
  75.       If .Cells(e, "F") Like "WG*" Then
  76.             .Cells(e, "AA").Select
  77.             Selection.Cut
  78.             .Cells(e, "K").Select
  79.             ActiveSheet.Paste
  80.       End If
  81.     Next


  82. End With
複製代碼



作者: rr09192084    時間: 2016-1-23 01:32 PM

本帖最後由 rr09192084 於 2016-1-23 01:38 PM 編輯

我記得以前這個問題就已經出現過了,要使用With就要把Sheet切換到那一張工作底稿上。
如:
  1. Set RepSht = Sheets("FMC")
  2. RepSht.Select
複製代碼
程式的最後再切換回來,不然就要用直接指定Sheet的方式。
另外,寫程式有點類似數學方程式的解法,相同的元素可以提出來,這個程式中每一個Case都會有這一段:
  1. .Cells(h, "AA").Select
  2. Selection.Cut
複製代碼
那麼就把這一段提出來,就像這樣:
  1. '把這一段提出來,如果沒有符合的條件,是不會執行貼上的動作的。
  2. .Cells(h, "AA").Select
  3. Selection.Cut
  4. Select Case .Cells(h, "F").Value
  5.     Case "TBG1"
  6.      .Cells(h, "H").Select
  7.      ActiveSheet.Paste
  8.     Case "PGH1"
  9.      .Cells(h, "I").Select
  10.      ActiveSheet.Paste
  11.     Case "SLS1"
  12.      .Cells(h, "J").Select
  13.      ActiveSheet.Paste
  14.     Case "DE01"
  15.      .Cells(h, "L").Select
  16.      ActiveSheet.Paste
  17. End Select
複製代碼

作者: v03586    時間: 2016-1-24 12:29 AM

本帖最後由 v03586 於 2016-1-24 12:30 AM 編輯
rr09192084 發表於 2016-1-23 01:32 PM
我記得以前這個問題就已經出現過了,要使用With就要把Sheet切換到那一張工作底稿上。
如:程式的最後再切換 ...

感謝大大指教...又讓我完成一項功能!!!!

剩下兩樣功能是否方便協助指教一下嗎
Q1.欄位線的劃置能全部細線條 , 依照B/D No 不同畫粗線條嗎?
   目前好像不同的MO 畫粗線
如圖片 原本是這樣
[attach]112714506[/attach]

讓他變成這種劃線方式
[attach]112714505[/attach]

1. 新增功能
   1-1. 程式中報表上CUSTNAME 欄位(V欄位)中如果只有 CSP / L1 / L2 / 字串則整個刪除
   1-2. 保留 ENG / HQCSP / HQ-CSP/ HQ-L1 / HQ-L2 / HQL1 / HQL2
   1-3. 然後移去ENG 移至ENG資料表, HQ CSP系列移至CSP資料表, HQ L1 / HQ L2 系列移至Other資料表
[attach]112714515[/attach]

  1. Dim UType%
  2. Sub 新報表_匯入()

  3. Dim xFile$, x As New Application, xB As Workbook, xS As Worksheet
  4. Dim RepSht As Worksheet, xR As Range, xLab As Range, xAddress$
  5. Set RepSht = Sheets("FMC")
  6. Application.ScreenUpdating = False
  7. RepSht.UsedRange.EntireRow.Delete
  8.     Dim currentPKG, currentDevice, whichFirst As String
  9.     Dim index As Integer
  10.     Dim hasReport As Boolean
  11.     title_row = 8
  12.     hasReport = False
  13.     For i = 1 To Workbooks.Count
  14.         With Workbooks(i).Sheets(1)
  15.             If .Range("A" & title_row).Value Like "LOTID*" And .Range("D" & title_row).Value Like "TYPE*" And .Range("M" & title_row) Like "QTY*" Then
  16.                 Set xS = Workbooks(i).Sheets(1)
  17.                 hasReport = True
  18.                 i = Workbooks.Count + 1
  19.             End If
  20.         End With
  21.     Next i
  22.     If hasReport = False Then MsgBox "找不到報表檔! ": Exit Sub
  23.     R = xS.Cells(Rows.Count, 1).End(xlUp).Row + 5
  24. With RepSht
  25.      .Range("A1:A" & R) = xS.Range("AJ1:AJ" & R).Value  'pkg
  26.      .Range("B1:B" & R) = xS.Range("B1:B" & R).Value 'MO
  27.      
  28.      .Range("C1:C" & R).NumberFormatLocal = "@"   'Date time
  29.      .Range("C1:C" & R) = xS.Range("L1:L" & R).Value   'Date time
  30.      
  31.      .Range("D1:D" & R) = xS.Range("A1:A" & R).Value 'LOTID

  32.      .Range("E1:E" & R) = xS.Range("D1:D" & R).Value  'DIE TYPE
  33.      .Range("F1:F" & R) = xS.Range("P1:P" & R).Value   'STEP
  34.      .Range("G1:G" & R) = xS.Range("M1:M" & R).Value  ' MO QTY
  35.      .Range("AA1:AA" & R) = xS.Range("Q1:Q" & R).Value   '  QTY
  36.      .Range("H8").Value = "TBG1"
  37.      .Range("I8").Value = "PGH1"
  38.      .Range("J8").Value = "SLS1"
  39.      .Range("K8").Value = "WG"
  40.      .Range("L8").Value = "DE01"
  41.      .Range("M8").Value = "WM01"
  42.      .Range("N8").Value = "FL01"
  43.      .Range("O8").Value = "LWS1"
  44.      .Range("P8").Value = "WS01"
  45.      .Range("Q8").Value = "UTI1"
  46.      .Range("R8").Value = "VS01"
  47.      .Range("S8").Value = "QVS1"
  48.      .Range("T8").Value = "RQVS1"
  49.      .Range("U8").Value = "DB"
  50.      .Range("V1:W" & R) = xS.Range("E1:F" & R).Value  'CUST DEVICE
  51.      .Range("X1:X" & R) = xS.Range("AD1:AD" & R).Value  'Substrate
  52.      .Range("Y1:Y" & R) = xS.Range("AE1:AE" & R).Value  'B/D No
  53.      .Range("Z1:Z" & R) = xS.Range("AQ1:AQ" & R).Value  'flow
  54.      .Range("A8").Value = "PKG"
  55.      .Range("A7").Value = ""
  56.      .Range("X8").Value = "Substrate"
  57.      .Range("X7").Value = ""
  58.      .Range("Y8").Value = "B/D No."
  59.      .Range("Y7").Value = ""
  60.      .Range("D2").Value = ""
  61.      .Range("AA8").Value = ""
  62.      .Range("A1").Value = "1ST Flow On Hand Report"
  63.      .Range("A2").Value = Now()
  64. End With

  65. Dim RRR&, xAArea As Range, xRRR As Range, xHH As Range, Q, TTTT, XXX
  66. RRR = [FMC!A65536].End(xlUp).Row: If RRR < 9 Then Exit Sub
  67. Set xAArea = Sheets("FMC").Range("A9:A" & RRR)
  68. For Each xRRR In xAArea
  69.     Q = xRRR(1, 26)
  70.     Q = Mid(Q & ",QVS", InStr(Q, "QVS") + 4) '取 QVS 以後字串
  71.     For Each TTTT In Array("SPC", "SCL")
  72.         XXX = InStr(Q, TTTT): If XXX > 0 Then xRRR(1, 26) = Left(Q, XXX + 2): Exit For
  73.     Next
  74. Next
  75. With RepSht
  76. '     For g = 3500 To 8 Step -1
  77. '        If .Cells(g, "V") Like "*CSP*" Or .Cells(g, "V") Like "*L1*" Or .Cells(g, "V") Like "*L2*" _
  78. '           Or .Cells(g, "V") Like "*ENG*" Or .Cells(g, "A") Like "LQFP*" Or .Cells(g, "A") Like "PLCC*" _
  79. '           Or .Cells(g, "A") Like "SOP*" Or .Cells(g, "A") Like "SSOP*" Or .Cells(g, "A") Like "TSOP*" _
  80. '           Or .Cells(g, "A") Like "TSSOP*" Or .Cells(g, "A") Like "TFBGA*" Then
  81. '            .Rows(g).Delete
  82. '        End If
  83. '     Next
  84. RepSht.Select
  85.   For h = 9 To 3500
  86.     .Cells(h, "AA").Select
  87.     Selection.Cut
  88.     Select Case .Cells(h, "F").Value
  89.     Case "TBG1"
  90.      .Cells(h, "H").Select
  91.      ActiveSheet.Paste
  92.     Case "PGH1"
  93.      .Cells(h, "I").Select
  94.      ActiveSheet.Paste
  95.     Case "SLS1"
  96.      .Cells(h, "J").Select
  97.      ActiveSheet.Paste
  98.     Case "DE01"
  99.      .Cells(h, "L").Select
  100.      ActiveSheet.Paste
  101.     Case "WM01"
  102.      .Cells(h, "L").Select
  103.      ActiveSheet.Paste
  104.     Case "FL01"
  105.      .Cells(h, "N").Select
  106.      ActiveSheet.Paste
  107.     Case "LWS1"
  108.      .Cells(h, "O").Select
  109.      ActiveSheet.Paste
  110.     Case "WS01"
  111.      .Cells(h, "P").Select
  112.      ActiveSheet.Paste
  113.     Case "UTI1"
  114.      .Cells(h, "Q").Select
  115.      ActiveSheet.Paste
  116.     Case "VS01"
  117.      .Cells(h, "R").Select
  118.      ActiveSheet.Paste
  119.     Case "QVS1"
  120.      .Cells(h, "S").Select
  121.      ActiveSheet.Paste
  122.     Case "RQVS1"
  123.      .Cells(h, "T").Select
  124.      ActiveSheet.Paste
  125.     Case "DB"
  126.      .Cells(h, "U").Select
  127.      ActiveSheet.Paste
  128.    End Select
  129.   Next
  130.     For e = 9 To 3500
  131.       If .Cells(e, "F") Like "WG*" Then
  132.             .Cells(e, "AA").Select
  133.             Selection.Cut
  134.             .Cells(e, "K").Select
  135.             ActiveSheet.Paste
  136.       End If
  137.     Next
  138. End With
  139. 'xB.Close 0
  140. Dim RR&, xArea As Range, xRR As Range, xH As Range, T, TT, XX
  141. RR = [FMC!A65536].End(xlUp).Row: If RR < 9 Then Exit Sub
  142. Set xArea = Sheets("FMC").Range("A9:A" & R)
  143. For Each xRR In xArea
  144.     T = xRR(1, 25): xRR(1, 25) = Mid(T, InStr(T, "-") + 1)
  145.     xRR(1, 24) = Right(xRR(1, 24), 9)
  146.       
  147.     T = xRR(1, 5):  T = Left(T, 2) & "-" & Mid(T, 24, 1) & "-" & Mid(T, 23, 4)
  148. Next
  149. xArea.Resize(, 26).Sort Key1:=xArea(1, 1), Order1:=xlAscending, _
  150.                        Key2:=xArea(1, 25), Order2:=xlAscending, Header:=xlNo
  151. Application.DisplayAlerts = False
  152. For Each xRR In xArea
  153.     If xRR & xRR(1, 2) <> xRR(0) & xRR(0, 2) Then Set xH = xRR
  154.     If xRR & xRR(1, 2) <> xRR(2) & xRR(2, 2) Then
  155.       Range(xH, xRR).Merge: Range(xH(1, 2), xRR(1, 2)).Merge
  156.       Range(xH, xRR).Merge: Range(xH(1, 3), xRR(1, 3)).Merge
  157.       Range(xH, xRR).Merge: Range(xH(1, 7), xRR(1, 7)).Merge
  158.       Range(xH, xRR).Merge: Range(xH(1, 22), xRR(1, 22)).Merge
  159.       Range(xH, xRR).Merge: Range(xH(1, 23), xRR(1, 23)).Merge
  160.       Range(xH, xRR).Merge: Range(xH(1, 24), xRR(1, 24)).Merge
  161.       Range(xH, xRR).Merge: Range(xH(1, 25), xRR(1, 25)).Merge
  162.       Range(xH, xRR).Merge: Range(xH(1, 26), xRR(1, 26)).Merge
  163.       Range(xH, xRR(1, 26)).Borders.LineStyle = 1
  164.       For i = 7 To 10
  165.           Range(xH, xRR(1, 26)).Borders(i).Weight = xlMedium
  166.       Next i
  167.     End If
  168. Next
  169. With RepSht
  170.     Sheets("FMC").Select
  171.     Cells.Select
  172.     Selection.Font.Size = 14
  173.     With Selection.Font
  174.         .Name = "Arial"
  175.         .Size = 14
  176.         .Strikethrough = False
  177.         .Superscript = False
  178.         .Subscript = False
  179.         .OutlineFont = False
  180.         .Shadow = False
  181.         .Underline = xlUnderlineStyleNone
  182.         .ThemeColor = xlThemeColorLight1
  183.         .TintAndShade = 0
  184.         .ThemeFont = xlThemeFontNone
  185.     End With
  186.     Range("A8:Z8").Select
  187.     With Selection.Interior
  188.         .Pattern = xlSolid
  189.         .PatternColorIndex = xlAutomatic
  190.         .Color = 255
  191.         .TintAndShade = 0
  192.         .PatternTintAndShade = 0
  193.     End With
  194.     With Selection.Font
  195.         .ThemeColor = xlThemeColorDark1
  196.         .TintAndShade = 0
  197.     End With
  198. End With
  199.     Range("A8").Select
  200.     ActiveWindow.Zoom = 63

  201. Call 調整
  202.    
  203. End Sub

  204. Sub 報表_清除()
  205. Sheets("FMC").UsedRange.EntireRow.Delete
  206. End Sub

  207. Sub 調整()
  208. Dim RepSht As Worksheet
  209. Set RepSht = Sheets("FMC")
  210. With RepSht
  211.     Columns("A:A").Select
  212.     Selection.ColumnWidth = 30
  213.     Columns("B:B").Select
  214.     Selection.ColumnWidth = 11.63
  215.     Columns("C:C").Select
  216.     Selection.ColumnWidth = 16
  217.     Columns("D:D").Select
  218.     Selection.ColumnWidth = 20.88
  219.     Columns("E:E").Select
  220.     Selection.ColumnWidth = 8.25
  221.     Columns("F:F").Select
  222.     Selection.ColumnWidth = 9.25
  223.     Columns("G:G").Select
  224.     Selection.ColumnWidth = 10
  225.     Selection.NumberFormatLocal = "#,##0_ "
  226.     Columns("H:U").Select
  227.     Selection.ColumnWidth = 8.63
  228.     Columns("V:V").Select
  229.     Selection.ColumnWidth = 40.38
  230.     ActiveWindow.SmallScroll ToRight:=11
  231.     Columns("W:W").Select
  232.     Selection.ColumnWidth = 59.75
  233.     Columns("X:X").Select
  234.     Selection.ColumnWidth = 15.5
  235.     Columns("Y:Y").Select
  236.     Selection.ColumnWidth = 10.5
  237.     ActiveWindow.SmallScroll ToRight:=4
  238.     Columns("Z:Z").Select
  239.     Selection.ColumnWidth = 93.38
  240.     Range("A7").Select
  241. End With

  242. End Sub
複製代碼








歡迎光臨 伊莉討論區 (http://a401.file-static.com/) Powered by Discuz!