我試圖採取精細過濾和刪除,我必須每天都做同一個原始數據報告中關於減少時儘可能多的它,因爲我可以到一個單一的按鈕單擊。過濾掉原始數據報告通過基本的宏
我相信我已經做了最該通過一個簡單的錄製的宏(如下圖所示),但它會在某些項目有時會離開的,我想刪除的項目。看看這段代碼,我認爲這可能歸因於這樣一個事實,即當宏正在應用過濾器時,它試圖刪除內容時所尋找的起始行並不固定。所以我的問題是,我應該只使用基於當前擁有過濾器的行的偏移值?或者這不會工作?
當我刪除標準「POR」「<> BGR」和「=日出地球」時出現問題我認爲這是因爲這些命令後面的選擇函數具有可能不總是可變的行號是真的
Sub ProgMisr()
'
' ProgMisr Macro
'
' Keyboard Shortcut: Ctrl+Shift+M
'
Columns("A:A").Select
Selection.Delete Shift:=xlToLeft
ActiveWindow.ScrollColumn = 2
Range("I:I,K:K,L:L").Select
Range("L1").Activate
Selection.Delete Shift:=xlToLeft
ActiveWindow.ScrollColumn = 1
Range("B6").Select
Selection.AutoFilter
ActiveSheet.Range("$A$6:$I$5761").AutoFilter Field:=2, Criteria1:="<>EHD*" _
, Operator:=xlAnd, Criteria2:="<>ESD*"
Rows("7:7").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
ActiveSheet.Range("$A$6:$I$1412").AutoFilter Field:=2
Range("F3").Select
ActiveSheet.Range("$A$6:$I$1412").AutoFilter Field:=6, Criteria1:=Array(_
"Missing Audio", "Missing Audio/Subs", "Missing Subs"), Operator:= _
xlFilterValues
ActiveSheet.Range("$A$6:$I$1412").AutoFilter Field:=3, Criteria1:="=DCBU", _
Operator:=xlOr, Criteria2:="=TLBA"
ActiveSheet.Range("$A$6:$I$1412").AutoFilter Field:=7, Criteria1:="="
Rows("13:13").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
ActiveSheet.Range("$A$6:$I$1069").AutoFilter Field:=7
Range("H1").Select
ActiveSheet.Range("$A$6:$I$1069").AutoFilter Field:=8, Criteria1:="<>*BGR*" _
, Operator:=xlAnd
Rows("66:66").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
ActiveSheet.Range("$A$6:$I$1059").AutoFilter Field:=8
ActiveSheet.Range("$A$6:$I$1059").AutoFilter Field:=3
ActiveSheet.Range("$A$6:$I$1059").AutoFilter Field:=7, Criteria1:="POR"
Rows("12:12").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
ActiveSheet.Range("$A$6:$I$809").AutoFilter Field:=7
ActiveSheet.Range("$A$6:$I$809").AutoFilter Field:=6, Criteria1:= _
"Missing Subs"
Rows("7:7").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
ActiveSheet.Range("$A$6:$I$133").AutoFilter Field:=6, Criteria1:= _
"=Missing Audio", Operator:=xlOr, Criteria2:="=Missing Audio/Subs"
Range("F2").Select
ActiveSheet.Range("$A$6:$I$133").AutoFilter Field:=1, Criteria1:= _
"=*Sunrise Earth*", Operator:=xlAnd
Rows("17:17").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
ActiveSheet.Range("$A$6:$I$112").AutoFilter Field:=1
ActiveSheet.Range("$A$6:$I$112").AutoFilter Field:=7, Criteria1:="ENG"
ActiveSheet.Range("$A$6:$I$112").AutoFilter Field:=3, Criteria1:=Array(_
"AHPL", "APPL", "CIPO", "DPOL", "IDPL", "SCPO", "TLPO", "WOIT"), Operator:=xlFilterValues
Rows("7:7").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
ActiveSheet.Range("$A$6:$I$55").AutoFilter Field:=3
Range("B11").Select
End Sub
編輯:新宏代碼
Sub ProgMisr()
'
' ProgMisr Macro
'
' Keyboard Shortcut: Ctrl+Shift+M
'
Columns("A:A").Select
Selection.Delete Shift:=xlToLeft
ActiveWindow.ScrollColumn = 2
Range("I:I,K:K,L:L").Select
Range("L1").Activate
Selection.Delete Shift:=xlToLeft
ActiveWindow.ScrollColumn = 1
LastRow = Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
Range("B6").Select
Selection.AutoFilter
ActiveSheet.Range("$A$6:$I$" & LastRow).AutoFilter Field:=2, Criteria1:="<>EHD*" _
, Operator:=xlAnd, Criteria2:="<>ESD*"
VisibleCell = Range("A2:I" & LastRow + 1).SpecialCells(xlCellTypeVisible).Cells(1).Row
RowsToSelect = VisibleCell.Row
Rows(RowsToSelect & ":" & RowsToSelect).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
ActiveSheet.Range("$A$6:$I$" & LastRow).AutoFilter Field:=2
Range("F3").Select
ActiveSheet.Range("$A$6:$I$" & LastRow).AutoFilter Field:=6, Criteria1:=Array(_
"Missing Audio", "Missing Audio/Subs", "Missing Subs"), Operator:= _
xlFilterValues
ActiveSheet.Range("$A$6:$I$" & LastRow).AutoFilter Field:=3, Criteria1:="=DCBU", _
Operator:=xlOr, Criteria2:="=TLBA"
ActiveSheet.Range("$A$6:$I$" & LastRow).AutoFilter Field:=7, Criteria1:="="
VisibleCell = Range("A2:I" & LastRow + 1).SpecialCells(xlCellTypeVisible).Cells(1).Row
RowsToSelect = VisibleCell.Row
Rows(RowsToSelect & ":" & RowsToSelect).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
ActiveSheet.Range("$A$6:$I$" & LastRow).AutoFilter Field:=7
Range("H1").Select
ActiveSheet.Range("$A$6:$I$" & LastRow).AutoFilter Field:=8, Criteria1:="<>*BGR*" _
, Operator:=xlAnd
VisibleCell = Range("A2:I" & LastRow + 1).SpecialCells(xlCellTypeVisible).Cells(1).Row
RowsToSelect = VisibleCell.Row
Rows(RowsToSelect & ":" & RowsToSelect).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
ActiveSheet.Range("$A$6:$I$ & LastRow").AutoFilter Field:=8
ActiveSheet.Range("$A$6:$I$ & LastRow").AutoFilter Field:=3
ActiveSheet.Range("$A$6:$I$ & LastRow").AutoFilter Field:=7, Criteria1:="POR"
VisibleCell = Range("A2:I" & LastRow + 1).SpecialCells(xlCellTypeVisible).Cells(1).Row
RowsToSelect = VisibleCell.Row
Rows(RowsToSelect & ":" & RowsToSelect).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
ActiveSheet.Range("$A$6:$I$ & LastRow").AutoFilter Field:=7
ActiveSheet.Range("$A$6:$I$ & LastRow").AutoFilter Field:=6, Criteria1:= _
"Missing Subs"
VisibleCell = Range("A2:I" & LastRow + 1).SpecialCells(xlCellTypeVisible).Cells(1).Row
RowsToSelect = VisibleCell.Row
Rows(RowsToSelect & ":" & RowsToSelect).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
ActiveSheet.Range("$A$6:$I$" & LastRow).AutoFilter Field:=6, Criteria1:= _
"=Missing Audio", Operator:=xlOr, Criteria2:="=Missing Audio/Subs"
Range("F2").Select
ActiveSheet.Range("$A$6:$I$" & LastRow).AutoFilter Field:=1, Criteria1:= _
"=*Sunrise Earth*", Operator:=xlAnd
VisibleCell = Range("A2:I" & LastRow + 1).SpecialCells(xlCellTypeVisible).Cells(1).Row
RowsToSelect = VisibleCell.Row
Rows(RowsToSelect & ":" & RowsToSelect).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
ActiveSheet.Range("$A$6:$I$" & LastRow).AutoFilter Field:=1
ActiveSheet.Range("$A$6:$I$" & LastRow).AutoFilter Field:=7, Criteria1:="ENG"
ActiveSheet.Range("$A$6:$I$" & LastRow).AutoFilter Field:=3, Criteria1:=Array(_
"AHPL", "APPL", "CIPO", "DPOL", "IDPL", "SCPO", "TLPO", "WOIT"), Operator:=xlFilterValues
VisibleCell = Range("A2:I" & LastRow + 1).SpecialCells(xlCellTypeVisible).Cells(1).Row
RowsToSelect = VisibleCell.Row
Rows(RowsToSelect & ":" & RowsToSelect).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
ActiveSheet.Range("$A$6:$I$" & LastRow).AutoFilter Field:=3
Range("B11").Select
End Sub
編輯2:
Sub ProgMisr()
'
' ProgMisr Macro
'
' Keyboard Shortcut: Ctrl+Shift+M
'
Columns("A:A").Select
Selection.Delete Shift:=xlToLeft
ActiveWindow.ScrollColumn = 2
Range("I:I,K:K,L:L").Select
Range("L1").Activate
Selection.Delete Shift:=xlToLeft
ActiveWindow.ScrollColumn = 1
LastRow = Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
Range("B6").Select
Selection.AutoFilter
ActiveSheet.Range("$A$6:$I$" & LastRow).AutoFilter Field:=2, Criteria1:="<>EHD*" _
, Operator:=xlAnd, Criteria2:="<>ESD*"
VisibleCell = Range("A7:I" & LastRow + 1).SpecialCells(xlCellTypeVisible).Cells(1).Row
Rows(VisibleCell & ":" & VisibleCell).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
ActiveSheet.Range("$A$6:$I$" & LastRow).AutoFilter Field:=2
Range("F3").Select
ActiveSheet.Range("$A$6:$I$" & LastRow).AutoFilter Field:=6, Criteria1:=Array(_
"Missing Audio", "Missing Audio/Subs", "Missing Subs"), Operator:= _
xlFilterValues
ActiveSheet.Range("$A$6:$I$" & LastRow).AutoFilter Field:=3, Criteria1:="=DCBU", _
Operator:=xlOr, Criteria2:="=TLBA"
ActiveSheet.Range("$A$6:$I$" & LastRow).AutoFilter Field:=7, Criteria1:="="
VisibleCell = Range("A7:I" & LastRow + 1).SpecialCells(xlCellTypeVisible).Cells(1).Row
Rows(VisibleCell & ":" & VisibleCell).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
ActiveSheet.Range("$A$6:$I$" & LastRow).AutoFilter Field:=7
Range("H1").Select
ActiveSheet.Range("$A$6:$I$" & LastRow).AutoFilter Field:=8, Criteria1:="<>*BGR*" _
, Operator:=xlAnd
VisibleCell = Range("A7:I" & LastRow + 1).SpecialCells(xlCellTypeVisible).Cells(1).Row
Rows(VisibleCell & ":" & VisibleCell).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
ActiveSheet.Range("$A$6:$I$" & LastRow).AutoFilter Field:=8
ActiveSheet.Range("$A$6:$I$" & LastRow).AutoFilter Field:=3
ActiveSheet.Range("$A$6:$I$" & LastRow).AutoFilter Field:=7, Criteria1:="POR"
VisibleCell = Range("A7:I" & LastRow + 1).SpecialCells(xlCellTypeVisible).Cells(1).Row
Rows(VisibleCell & ":" & VisibleCell).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
ActiveSheet.Range("$A$6:$I$" & LastRow).AutoFilter Field:=7
ActiveSheet.Range("$A$6:$I$" & LastRow).AutoFilter Field:=6, Criteria1:= _
"Missing Subs"
VisibleCell = Range("A2:I" & LastRow + 1).SpecialCells(xlCellTypeVisible).Cells(1).Row
Rows(VisibleCell & ":" & VisibleCell).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
ActiveSheet.Range("$A$6:$I$" & LastRow).AutoFilter Field:=6, Criteria1:= _
"=Missing Audio", Operator:=xlOr, Criteria2:="=Missing Audio/Subs"
Range("F2").Select
ActiveSheet.Range("$A$6:$I$" & LastRow).AutoFilter Field:=1, Criteria1:= _
"=*Sunrise Earth*", Operator:=xlAnd
VisibleCell = Range("A2:I" & LastRow + 1).SpecialCells(xlCellTypeVisible).Cells(1).Row
Rows(VisibleCell & ":" & VisibleCell).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
ActiveSheet.Range("$A$6:$I$" & LastRow).AutoFilter Field:=1
ActiveSheet.Range("$A$6:$I$" & LastRow).AutoFilter Field:=7, Criteria1:="ENG"
ActiveSheet.Range("$A$6:$I$" & LastRow).AutoFilter Field:=3, Criteria1:=Array(_
"AHPL", "APPL", "CIPO", "DPOL", "IDPL", "SCPO", "TLPO", "WOIT"), Operator:=xlFilterValues
VisibleCell = Range("A2:I" & LastRow + 1).SpecialCells(xlCellTypeVisible).Cells(1).Row
Rows(VisibleCell & ":" & VisibleCell).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
ActiveSheet.Range("$A$6:$I$" & LastRow).AutoFilter Field:=3
Range("B11").Select
End Sub
宏是有點亂所以其種很難理解你想什麼去完成。你能說出你想要刪除/過濾哪些數據嗎?它們是位於表單上的數據,這樣宏就更有意義了。 –
當然,我現在更新我的問題 – Chris