ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

Ū¨ú¤ÎÂkÃþ¤Î®Ø綫®æ¦¡

¦^´_ 19# Andy2483


    ¥X²{¤§«eªº°ÝÃD¡A³Ì«á¤@¦æÅܦ¨²Ä¤G­¶¡A内®e¦³¶Ã½X¡A¤£ª¾¹D«ç¼Ë§ï¡C
Option Explicit
Sub TEST()
Dim Brr(1 To 100, 1 To 14), A, Z, Q, P, i&, j%, R&, C%, N&, x%, T$, T14$, T15$, T5$, V8&, V9&, V10#, Tp1$, Tp3$, Tp5$, Y&, SS$, 夹肈õä¤àÇx££#
Dim PGNr, Rackr, Itemr, PGr, DPLs As Worksheet, xR As Range, xRs As Range, TT$, TH#, ii, RH, Sh#, xRc As Range, xRe As Range
Set Z = CreateObject("Scripting.Dictionary"): Application.ScreenUpdating = False: Application.DisplayAlerts = False: Sh = Rows(17).RowHeight / 32
夹肈õä¤àÇx££ = [O1]: PGNr = [PGN!A1].CurrentRegion: Rackr = [Rack!A1].CurrentRegion: Itemr = [Item!A1].CurrentRegion: PGr = [PG!A1].CurrentRegion
Set DPLs = Sheets("DPL"): DPLs.Activate: T = [J3]: DPLs.UsedRange.Offset(19).EntireRow.Delete: Set xR = [A20]
Cells.VerticalAlignment = xlCenter: ActiveSheet.ResetAllPageBreaks: [A1].Activate: For i = 1 To 19: TH = TH + Rows(i).RowHeight: Next
For i = 2 To UBound(PGr)
   If Z(PGr(i, 1) & "^") = "" Then Z(PGr(i, 1) & "^") = PGr(i, 2) Else MsgBox "PG " & PGr(i, 1) & " ¬¾": Exit Sub
Next
For i = 2 To UBound(Rackr)
   If Rackr(i, 11) <> T Then GoTo i01
   T14 = Rackr(i, 14): T5 = Rackr(i, 5): T15 = Rackr(i, 15)
   If Not Z.Exists(T15) Then R = N Mod 3 + 1: C = N \ 3: N = N + 1: Brr(R, Array(1, 3, 4)(C)) = T15: Z(T15) = ""
   If InStr("," & Z(T14 & "/GD") & ",", "," & T15 & ",") = 0 Then Z(T14 & "/GD") = Z(T14 & "/GD") & "," & T15
   If InStr("," & Z(T14 & "/RN") & ",", "," & T5 & ",") = 0 Then Z(T14 & "/RN") = Z(T14 & "/RN") & "," & T5: Z(T5 & "|") = i Else MsgBox "Rack " & T5 & " ¬¾": Exit Sub
i01: Next
DPLs.[G12].Resize(3, 4) = Brr: DPLs.[G15] = "TOTAL " & N & " X 45'HC CONTAINER": N = 0
For i = 2 To UBound(PGNr)
   If PGNr(i, 1) <> T Then GoTo i02
   If Z.Exists(PGNr(i, 2) & "/GD") Then Z(PGNr(i, 2) & "/GD") = "CONTAINER NO.:" & Mid(Z(PGNr(i, 2) & "/GD"), 2) & vbCrLf & PGNr(i, 3)
i02: Next
For i = 2 To UBound(Itemr)
   If Z.Exists(Itemr(i, 3) & "|") Then Z(Itemr(i, 3) & "|") = Z(Itemr(i, 3) & "|") & "," & i
Next
For Each A In Z.KEYS
   If Right(A, 3) <> "/RN" Then GoTo A01 Else Q = Split(Z(A), ","): xR = Z(Split(A, "/RN")(0) & "/GD")
   With xR.Resize(, 14): .Merge: .Font.Size = 9: .Font.Bold = True: .Rows.RowHeight = 52 * Sh: End With
   For i = 1 To UBound(Q)
      Set xR = xR(2): xR.Resize(1, 14).Interior.ColorIndex = 15: xR.Resize(1, 14).Font.Bold = True: xR.Rows.RowHeight = 27 * Sh
      With xR.Resize(1, 4): .Merge: .Font.Size = 12:  .Value = "'" & Q(i): End With
      xR(1, 6).Resize(, 2).Merge: xR(1, 10).Resize(, 5).Merge
      P = Split(Z(Q(i) & "|"), ","): R = Val(P(0))
      xR(1, 8) = Val(Rackr(R, 6)): xR(1, 9) = Val(Rackr(R, 7)): xR(1, 10) = Rackr(R, 8) & " x " & Rackr(R, 9) & " x " & Rackr(R, 10)
      V8 = V8 + xR(1, 8): V9 = V9 + xR(1, 9): V10 = V10 + (Val(Rackr(R, 8)) * Val(Rackr(R, 9)) * Val(Rackr(R, 10)) / 10 ^ 9): Set xRs = xR(2, 8): Set xRs = xR(2, 1)
      For j = 1 To UBound(P)
         Tp1 = Itemr(P(j), 5): Tp3 = Z(Itemr(P(j), 6) & "^"): Tp5 = Itemr(P(j), 4)
         Y = Z(Q(i) & "/" & Tp1 & "/" & Tp3 & "/" & Tp5)
         If Y = 0 Then
            Set xR = xR(2): xR.Resize(1, 14).Font.Size = 9: xR = Tp1: xR(1, 3) = Tp3: xR(1, 5) = Tp5: xR(1, 6) = Val(Itemr(P(j), 7))
            Z(Q(i) & "/" & Tp1 & "/" & Tp3 & "/" & Tp5) = xR.Row: xR.Rows.RowHeight = 27 * Sh: GoTo j01
         End If
         Cells(Y, 6) = Cells(Y, 6) + Val(Itemr(P(j), 7))
j01:  Next
      With Range(xRs, xR(1, 14))
         .Sort KEY1:=.Item(6), Order1:=1, Header:=2: .Sort KEY1:=.Item(5), Order1:=1, Key2:=.Item(3), Order2:=1, Key3:=.Item(1), Order2:=1, Header:=2
         For R = 1 To .Rows.Count: .Cells(R, 1).Resize(1, 2).Merge: .Cells(R, 3).Resize(1, 2).Merge: .Cells(R, 6).Resize(1, 2).Merge: .Cells(R, 8).Resize(1, 7).Merge: Next
      End With
   Next
   Set xR = xR(2)
A01: Next
Cells.VerticalAlignment = xlCenter: If ActiveSheet.VPageBreaks.Count + 1 = 2 Then ActiveSheet.VPageBreaks(1).DragOff Direction:=xlToRight, RegionIndex:=1
xR(1, 5) = "TOTAL": xR.Resize(, 4).Merge: xR(1, 5).Resize(, 3).Merge: xR(1, 8) = V8: xR(1, 9) = V9: xR(1, 10) = Round(V10, 2): xR(1, 10).Resize(1, 5).Merge: xR.Rows.RowHeight = 27 * Sh
With xR.Resize(1, 14): .Font.Size = 12: .Font.Bold = True: End With
ActiveSheet.Names.Add Name:="PrintArea", RefersTo:=Range([A1], xR(, 14)): ActiveSheet.PageSetup.PrintArea = "PrintArea"
For i = 20 To xR.Row '800-327.3=472.7 : 472.7/327.3=1.44
   TT = Cells(i, 3) & "/" & Cells(i, 5)
   If TT = "/" Then GoTo i03
   If TT = SS Or SS = "" Then
      If xRc Is Nothing Then Set xRc = Cells(i, 3): Set xRe = Cells(i, 5) Else Set xRc = Union(xRc, Cells(i, 3)): Set xRe = Union(xRe, Cells(i, 5))
   End If
i03: RH = RH + Cells(i, 1).RowHeight
   If Cells(i + 1, 3) & "/" & Cells(i + 1, 5) <> TT Or RH / TH > 夹肈õä¤àÇx££ Then
      If Not xRc Is Nothing Then
         If xRc.Count > 1 Then With Intersect(xRc, xRc.Offset(1)): .Merge: .Value = "": End With: xRe.Merge: xRe.VerticalAlignment = xlTop: xRc.Offset(, 5).Merge
      End If
      Set xRc = Nothing: Set xRe = Nothing: SS = Cells(i + 1, 3) & "/" & Cells(i + 1, 5)
   End If
   If RH / TH > 夹肈õä¤àÇx££ Then Cells(i + 1, 1).PageBreak = xlPageBreakManual: RH = 0
Next
Intersect(Range("PrintArea"), Range("PrintArea").Offset(19)).Borders.LineStyle = 1
Set Z = Nothing: Erase PGNr, Rackr, Itemr, PGr: Set xR = Nothing: Set xRs = Nothing: Set xRc = Nothing: Set xRe = Nothing
End Sub

TOP

¦^´_ 21# Andy2483


    ¦b­þ­Ó¦ì¸m¡A¦]爲¶Ã½X¡A§Ú¤À¿ì¤£¥X¡C

TOP

¦^´_ 23# Andy2483


    ¥i¥H¤F¡AÁÂÁ¡C

¥t¥~¦³­Ó°ÝÃD¡A§Ú¥Î¿ý»s¤è¦¡¼g¤F¤@­ÓVBA ¬O¦bªþ¥óùثإߨâ­Ó¼Ï¯Ã¤ÀªRªí¡C¤£¹L¹B¦æªº®É­Ô¦b¤U­±³o­Ó¦ì¸m¥d¦í¤F¡C   ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "sheet1!R1C1:R1048576C12", Version:=8).CreatePivotTable TableDestination:= _
        "sheet1!R1C26", TableName:="PivotTable21", DefaultVersion:=8
½ÐÀ°§Ú¬Ý¬Ý¬O­þùØ¥X²{°ÝÃD¡C
¥t¥~¯à¤£¯àÀ°¦£§ï¨}¤@¤U¡A
1) ÄæZ -AAªº¼Ï¯Ã¤ÀªRªí
¸ê®Æ¨Ó·½±qA1  - L1  :  A (ÄæB³Ì«á¤@¦æ¡^ -  L(ÄæB³Ì«á¤@¦æ¡^
Äæ¦ì²M³æ¡G
¦C ¡G SECTION & LENGTH
­È ¡G ¥[Á`QTY

2) ÄæAC-ADªº¼Ï¯Ã¤ÀªRªí
¸ê®Æ¨Ó·½±qN1  - V1  :  N (ÄæP³Ì«á¤@¦æ¡^ -  V(ÄæP³Ì«á¤@¦æ¡^
Äæ¦ì²M³æ¡G
¦C ¡G SECTION & LENGTH
­È ¡G ¥[Á`Q'TY

Sub Macro2()
  Application.CutCopyMode = False
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "sheet1!R1C1:R1048576C12", Version:=8).CreatePivotTable TableDestination:= _
        "sheet1!R1C26", TableName:="PivotTable21", DefaultVersion:=8
    Sheets("sheet1)").Select
    Cells(1, 26).Select
    With ActiveSheet.PivotTables("PivotTable21")
        .ColumnGrand = True
        .HasAutoFormat = True
        .DisplayErrorString = False
        .DisplayNullString = True
        .EnableDrilldown = True
        .ErrorString = ""
        .MergeLabels = False
        .NullString = ""
        .PageFieldOrder = 2
        .PageFieldWrapCount = 0
        .PreserveFormatting = True
        .RowGrand = True
        .SaveData = True
        .PrintTitles = False
        .RepeatItemsOnEachPrintedPage = True
        .TotalsAnnotation = False
        .CompactRowIndent = 1
        .InGridDropZones = False
        .DisplayFieldCaptions = True
        .DisplayMemberPropertyTooltips = False
        .DisplayContextTooltips = True
        .ShowDrillIndicators = True
        .PrintDrillIndicators = False
        .AllowMultipleFilters = False
        .SortUsingCustomLists = True
        .FieldListSortAscending = False
        .ShowValuesRow = False
        .CalculatedMembersInFilters = False
        .RowAxisLayout xlCompactRow
    End With
    With ActiveSheet.PivotTables("PivotTable21").PivotCache
        .RefreshOnFileOpen = False
        .MissingItemsLimit = xlMissingItemsDefault
    End With
    ActiveSheet.PivotTables("PivotTable21").RepeatAllLabels xlRepeatLabels
    ActiveWorkbook.ShowPivotTableFieldList = True
    With ActiveSheet.PivotTables("PivotTable21").PivotFields("SECTION")
        .Orientation = xlRowField
        .Position = 1
    End With
    With ActiveSheet.PivotTables("PivotTable21").PivotFields("LENGTH")
        .Orientation = xlRowField
        .Position = 2
    End With
    ActiveSheet.PivotTables("PivotTable21").AddDataField ActiveSheet.PivotTables( _
        "PivotTable21").PivotFields("QTY"), "Count of QTY", xlCount
    With ActiveSheet.PivotTables("PivotTable21").PivotFields("Count of QTY")
        .Caption = "Sum of QTY"
        .Function = xlSum
    End With
    ActiveWorkbook.ShowPivotTableFieldList = False
End Sub

pivot table.rar (20.52 KB)

TOP

¦^´_ 25# Andy2483


    ¦nªº¡AÁÂÁ¡C

TOP

¦^´_ 28# Andy2483


    ÁÂÁ¡A«e½ú«üÂI¡C

TOP

¥»©«³Ì«á¥Ñ 198188 ©ó 2024-2-26 09:38 ½s¿è

¦^´_ 28# Andy2483


§Ú¤µ¤Ñ¸Õ¤F¤@­Ó·sªº¡A¥X²{¬õ¦â³¡¤Àªº°ÝÃD¡C
¥ªÃä¶Â¦â¦rªº¬OVBA°õ¦æ¥X¨Óªº¡A¥kÃ䪺¬O·Q­nªºµ²ªG¡C

13.rar (152.06 KB)

TOP

¦^´_ 31# Andy2483


    ¥[¦b­þ­Ó¦ì¸m¡H³Ì«á¶Ü¡H

TOP

¦^´_ 31# Andy2483
¤§«e¤W¸ü¿ù¤Fªþ¥ó¡A³o­Óªþ¥ó¬O¹B¦æ¦Z³B²zªº®ÄªG¡C

VBA ¹B¦æ.rar (151.22 KB)

TOP

¦^´_ 34# Andy2483


    ¤£¦n·N«ä¡A¥[¤F¡A¥ª¤W¨¤°ÝÃD¤£¦s¦b¡A¥k¤U¤èTOTAL¨º­Ó¦a¤èªº°ÝÃDÁÙ¬O¦s¦b¡C

VBA ¹B¦æ.rar (151.92 KB)

TOP

¦^´_ 36# Andy2483


    Dim Brr(1 To 100, 1 To 14), A, Z, Q, P, i&, j%, R&, C%, N&, x%, T$, T14$, T15$, T5$, V8#, V9#, V10#, Tp1$, Tp3$, Tp5$, Y&, SS$, Tts#
­×§ï¤F¡AÁÙ¦³¬õ¦â¦r¨â³B°ÝÃD¡C

TOP

        ÀR«ä¦Û¦b : ¤£©È¨Æ¦h¡A¥u©È¦h¨Æ¡C
ªð¦^¦Cªí ¤W¤@¥DÃD