Option Explicit
Sub 刪除多餘空欄空列()
Dim s As Worksheet, i&, j%, R&, C%
'↑宣告變數:&是長整數,%是短整數
For Each s In Worksheets
'↑設逐項迴圈!令S變數是活頁簿裡的工作表
Application.Goto s.[A1]: R = 0: C = 0
'↑令游標跳到迴圈工作表的A1儲存格,令R變數歸零,令C變數歸零
With Range(s.[A1], s.UsedRange)
'↑以下是關於A1儲存格到有使用儲存格這範圍儲存格的程序
For j = 1 To .Cells.Columns.Count
'↑設順迴圈!令j從1 到該範圍的欄數
If R < Cells(Rows.Count, j).End(xlUp).Row Then R = Cells(Rows.Count, j).End(xlUp).Row
'↑如果R變數小於迴圈欄最後有內容儲存格的列號,就令R變數是該列號數
Next
If .Rows.Count > R + 1 Then Rows(R + 1 & ":" & .Rows.Count).Delete
'↑如果範圍列數大於 R變數+1!就令多餘的列刪除
For i = 1 To .Cells.Rows.Count
'↑設順迴圈!令i從1 到該範圍的列數
If C < Cells(i, Columns.Count).End(xlToLeft).Column Then C = Cells(i, Columns.Count).End(xlToLeft).Column
'↑如果C變數小於迴圈列最後有內容儲存格的欄號,就令C變數是該欄號數
Next
If .Columns.Count > C + 1 Then Range(Cells(1, C + 1), Cells(1, .Columns.Count)).EntireColumn.Delete
'↑如果範圍欄數大於 C變數+1!就令多餘的欄刪除
End With
Next
End Sub
Option Explicit
Sub 資料彙整入主頁篩選區()
Dim Brr, Crr, Z, Q, i&, j%, R&, N&, S, T$, E&, TT$
Set Z = CreateObject("Scripting.Dictionary")
With Sheets("主頁")
.Activate
If .AutoFilter Is Nothing Then [B17:P17].AutoFilter Else If .FilterMode = True Then .ShowAllData
With ActiveWindow
.FreezePanes = False
.ScrollRow = 13
.SplitRow = 5
.FreezePanes = True
End With
.UsedRange.Offset(17).EntireRow.Delete
.[B:D].NumberFormat = "@"
.[B:D].Font.Bold = True
End With
ReDim Crr(1 To 10000, 1 To 15)
Q = Array(Range([儲位!B3], [儲位!A65536].End(xlUp)), Range([儲位!E3], [儲位!D65536].End(xlUp)))
For Each Brr In Q
Brr = Brr
For i = 1 To UBound(Brr)
N = N + 1: T = Brr(i, 2): Crr(N, 1) = Brr(i, 1): Crr(N, 2) = T: Z(T) = N
Next
Next
E = N: Q = Array("1至588", "SUPER", "POWER", "POWER試產", "TEST", "待報廢", "報廢")
For Each S In Q
Brr = Sheets(S).[A1].CurrentRegion
For i = 3 To UBound(Brr)
R = Z(Brr(i, 1))
If Z.Exists(Brr(i, 2) & "|") Then TT = TT & " / " & S & "表_" & Brr(i, 2) Else Z(Brr(i, 2) & "|") = "A"
If R = 0 Then N = N + 1: R = N
For j = 1 To 14: Crr(R, j + 1) = Brr(i, j): Next
If R > E Then Crr(R, 1) = S
Next
Next
If N = 0 Then Exit Sub
If TT <> "" Then MsgBox "鋼板編號 " & Mid(TT, 4) & " 重複": Exit Sub
With [B18].Resize(N, 15): .Value = Crr: .Borders.LineStyle = 1: End With
End Sub
Sub 清除主頁篩選區資料()
With Sheets("主頁")
.Activate
If .AutoFilter Is Nothing Then [B17:P17].AutoFilter Else If .FilterMode = True Then .ShowAllData
With ActiveWindow: .FreezePanes = False: .ScrollRow = 1: .SplitRow = 17: .FreezePanes = True: End With
.UsedRange.Offset(17).EntireRow.Delete
End With
End Sub作者: aassddff736 時間: 2024-3-7 13:23
Option Explicit Sub 資料彙整入主頁篩選區()
Application.ScreenUpdating = False: Application.DisplayAlerts = False
Dim Arr, Brr, Crr(1 To 10000, 1 To 1), Z, Q, i&, j%, R&, N&, S, T$, E&, TT$, xR As Range
Set Z = CreateObject("Scripting.Dictionary")
With Sheets("主頁")
.Activate: If .AutoFilter Is Nothing Then [B17:Q17].AutoFilter Else If .FilterMode = True Then .ShowAllData
With ActiveWindow: .FreezePanes = False: .ScrollRow = 13: .SplitRow = 5: .FreezePanes = True: End With: .UsedRange.Offset(17).EntireRow.Delete
End With
Q = Array("1至588", "SUPER", "POWER", "POWER試產", "TEST", "待報廢", "報廢")
For Each S In Q
Set xR = [D65536].End(3)(2, 0): If Sheets(S).FilterMode = True Then Sheets(S).ShowAllData
R = Sheets(S).[B65536].End(3).Row - 2: Sheets(S).[A3].Resize(R, 14).Copy xR: If InStr("待報廢", S) Then xR.Resize(R, 1).Offset(, -1) = S
Next
Set Brr = Range([P18], [D65536].End(3)(1, -1)): Brr.Font.Size = 8: N = Brr.Rows.Count: Brr = Brr.Resize(10000).Resize(, 2)
For i = 1 To UBound(Brr): Z(Brr(i, 2)) = i: Next: Z.Remove ("")
Q = Array(Range([儲位!B3], [儲位!A65536].End(xlUp)), Range([儲位!E3], [儲位!D65536].End(xlUp)))
For Each Arr In Q
Arr = Arr
For i = 1 To UBound(Arr)
T = Arr(i, 2): If Z.Exists(T) Then Brr(Z(T), 1) = Arr(i, 1) Else N = N + 1: Brr(N, 1) = Arr(i, 1): Brr(N, 2) = Arr(i, 2)
Next
Next
With [B18].Resize(N, 2): .Value = Brr: .Resize(, 15).Borders.LineStyle = 1: .EntireRow.AutoFit: End With: Call 註解_調整至指定位置
End Sub Sub 註解_調整至指定位置()
Dim CO As Comment, SL&, ST&
For Each CO In ActiveSheet.Comments
With CO
With Range(.Parent.Address): SL = .Left + .Width + 10: ST = .Top + 10: End With: With .Shape: .Left = SL: .Top = ST: End With
.Shape.TextFrame.Characters.Font.Size = 12: .Shape.DrawingObject.AutoSize = True
End With
Next
Application.DisplayCommentIndicator = -1
End Sub Sub 清除主頁篩選區資料()
With Sheets("主頁")
.Activate: If .AutoFilter Is Nothing Then [B17:Q17].AutoFilter Else If .FilterMode = True Then .ShowAllData
With ActiveWindow: .FreezePanes = False: .ScrollRow = 1: .SplitRow = 17: .FreezePanes = True: End With: .UsedRange.Offset(17).EntireRow.Delete
End With
End Sub Sub 主頁篩選區資料_全部顯示()
With Sheets("主頁")
.Activate: If .AutoFilter Is Nothing Then [B17:Q17].AutoFilter Else If .FilterMode = True Then .ShowAllData
With ActiveWindow: .FreezePanes = False: .ScrollRow = 13: .SplitRow = 5: .FreezePanes = True: .ScrollRow = 1: End With
If .[D65536].End(3).Row = 17 Then Call 資料彙整入主頁篩選區
End With
End Sub Sub 空儲位()
Call 主頁篩選區資料_全部顯示: Selection.AutoFilter Field:=2, Criteria1:="<>": Selection.AutoFilter Field:=3, Criteria1:="="
End Sub Sub 沒有儲位的鋼板()
Call 主頁篩選區資料_全部顯示: Selection.AutoFilter Field:=3, Criteria1:="<>": Selection.AutoFilter Field:=2, Criteria1:="="
End Sub作者: aassddff736 時間: 2024-3-8 11:09
Sub 資料彙整入主頁篩選區()
Application.ScreenUpdating = False: Application.DisplayAlerts = False
Dim Arr, Brr, Crr(1 To 10000, 1 To 1), Z, Q, i&, j%, R&, N&, S, T$, E&, TT$, xR As Range
Set Z = CreateObject("Scripting.Dictionary")
With Sheets("主頁")
.Activate: If .AutoFilter Is Nothing Then [B17:Q17].AutoFilter Else If .FilterMode = True Then .ShowAllData
With ActiveWindow: .FreezePanes = False: .ScrollRow = 13: .SplitRow = 5: .FreezePanes = True: End With: .UsedRange.Offset(17).EntireRow.Delete
End With
Q = Array("1至588", "SUPER", "POWER", "POWER試產", "TEST", "待報廢", "報廢")
For Each S In Q
Set xR = [D65536].End(3)(2, 0): If Sheets(S).FilterMode = True Then Sheets(S).ShowAllData
R = Sheets(S).[B65536].End(3).Row - 2: Sheets(S).[A3].Resize(R, 14).Copy xR: If InStr("待報廢", S) Then xR.Resize(R, 1).Offset(, -1) = S
For i = 1 To xR.Resize(R, 1).Offset(, -2).Count
ActiveSheet.Hyperlinks.Add Anchor:=xR.Resize(R, 1).Offset(, 1)(i), Address:="", SubAddress:=S & "!A" & i + 2 & ":O" & i + 2
Next
Next
Set Brr = Range([P18], [D65536].End(3)(1, -1)): Brr.Font.Size = 8: Brr.Columns(3).Font.Size = 12: N = Brr.Rows.Count: Brr = Brr.Resize(10000).Resize(, 2)
For i = 1 To UBound(Brr): Z(Brr(i, 2)) = i: Next: Z.Remove ("")
Q = Array(Range([儲位!B3], [儲位!A65536].End(xlUp)), Range([儲位!E3], [儲位!D65536].End(xlUp)))
For Each Arr In Q
Arr = Arr
For i = 1 To UBound(Arr)
T = Arr(i, 2): If Z.Exists(T) Then Brr(Z(T), 1) = Arr(i, 1) Else N = N + 1: Brr(N, 1) = Arr(i, 1): Brr(N, 2) = Arr(i, 2)
Next
Next
With [B18].Resize(N, 2): .Value = Brr: .Resize(, 15).Borders.LineStyle = 1: .EntireRow.AutoFit: End With: Call 註解_調整至指定位置
End Sub作者: aassddff736 時間: 2024-3-8 14:25
將以下代碼植入 主頁 工作表模組下
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
With Target
Dim Ad$, Arr, Z, xR As Range, i&
Set Arr = Intersect([主頁!B17].CurrentRegion, [主頁!B18:D65536])
If Me.UsedRange.Rows.Count <= 17 Then Exit Sub
If .Columns.Count > 1 Then Exit Sub
Set xR = Intersect(Arr.Resize(, 1), .Cells): Arr.Resize(, 2).Validation.Delete
If Not xR Is Nothing Then
If .Count > 1 Then Exit Sub
If Trim(.Value) = "" Then Exit Sub Else Arr = Arr
Set Z = CreateObject("Scripting.Dictionary")
For i = 1 To UBound(Arr)
If Arr(i, 1) = .Value And Arr(i, 3) = "" Then Z(Arr(i, 2)) = ""
Next
With .Item(1, 2).Validation
If Z.Count > 0 Then .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=Join(Z.KEYS(), ",")
End With
Set Z = Nothing: Arr = Empty: Exit Sub
End If
Set xR = Intersect(Arr.Resize(, 2), .Cells)
If Not xR Is Nothing Then
If .Count > 1 Then Exit Sub
If .Value = "" Then Exit Sub Else Arr = Arr
Set Z = CreateObject("Scripting.Dictionary")
For i = 1 To UBound(Arr): Z(Arr(i, 1) & "/" & Arr(i, 2)) = i + 17: Next
If Z.EXISTS(.Item(1, 0) & "/" & .Value) Then Rows(Z(.Item(1, 0) & "/" & .Value)).Delete
Ad = .Cells(1, 2).Hyperlinks(1).SubAddress
Application.Goto Sheets(Split(Ad, "!")(0)).Range(Split(Ad, "!")(1))
Selection(1) = .Value: Set Z = Nothing: Arr = Empty
End If
End With
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Arr, Z, i&, xR As Range
With Target
Set Arr = Intersect([主頁!B17].CurrentRegion, [主頁!B18:D65536])
Set xR = Intersect(Arr.Resize(, 1), .Cells): Arr.Resize(, 1).Validation.Delete: Arr = Arr
If Not xR Is Nothing Then
Set Z = CreateObject("Scripting.Dictionary")
For i = 1 To UBound(Arr)
If Arr(i, 1) <> "" And Arr(i, 3) = "" Then Z(Arr(i, 1)) = ""
Next
With .Validation
If Z.Count > 0 Then .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=Join(Z.KEYS(), ","): Set Z = Nothing: Arr = Empty
End With
End If
End With
End Sub作者: aassddff736 時間: 2024-3-26 11:45
Option Explicit
Sub 不重複各欄明細()
Dim Brr, Crr, Z, Q, i&, j%, R&, T$, x%, Rm&
Set Z = CreateObject("Scripting.Dictionary")
Brr = Intersect([主頁!B17].CurrentRegion, [主頁!B17:P65536])
ReDim Crr(10000, 1 To UBound(Brr, 2))
For j = 1 To UBound(Brr, 2)
For i = 2 To UBound(Brr)
Q = Split(Brr(i, j) & Chr(10), Chr(10))
For x = 0 To UBound(Q) - 1
T = Trim(Q(x))
If Not Z.Exists(T) And T <> "" Then R = R + 1: Crr(R, j) = T: Z(T) = "": Rm = IIf(R > Rm, R, Rm)
Next
Next
Crr(0, j) = Brr(1, j): R = 0: Z.RemoveAll
Next
Workbooks.Add
With [A1].Resize(Rm + 1, UBound(Brr, 2))
.NumberFormat = "@": .Value = Crr: .EntireColumn.AutoFit
For j = 1 To UBound(Brr, 2): .Columns(j).Sort KEY1:=.Cells(1, j), Order1:=1, Header:=1: Next
End With
End Sub作者: aassddff736 時間: 2024-3-27 13:59