我的密码是
Sub Macro5()
'
' Macro5 Macro
'
Range("A7").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Columns.AutoFit
Range("A8").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=R4C2"
Range("A8").Select
Selection.Copy
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Paste
Range("A7").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.AutoFilter
Selection.Columns.AutoFit
ActiveWindow.SmallScroll ToRight:=15
ActiveSheet.Range("$A$7:$AC$38").AutoFilter Field:=20, Criteria1:="0"
ActiveSheet.Range("$A$7:$AC$38").AutoFilter Field:=22, Criteria1:="0"
ActiveWindow.SmallScroll ToRight:=-45
Range("A13").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.EntireRow.Delete
Cells.Select
Range("A22").Activate
Selection.AutoFilter
Range("A11").Select
Columns("E:E").Select
Application.CutCopyMode = False
Selection.Replace What:="Discovery Ads", Replacement:="Qua" & ChrW(777) & "ng Ca" & ChrW(769) & "o Kha" _
& ChrW(769) & "m Pha" & ChrW(769) _
, LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat _
:=False, ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
Columns("E:E").Select
Selection.Replace What:="Product Search Ad", Replacement:= _
"Qua" & ChrW(777) & "ng Ca" & ChrW(769) & "o Ti" _
& ChrW(768) & "m Kiê" & ChrW(769) & "m Sa" & ChrW(777) & "n Phâ" & ChrW( _
777) & "m", LookAt:=xlPart, SearchOrder:=xlByRows, _
MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False, _
FormulaVersion:=xlReplaceFormula2
Columns("E:E").Select
Selection.Replace What:="Shop Search Ad", Replacement:= _
"Qua" & ChrW(777) & "ng Ca" & ChrW(769) & "o Ti" _
& ChrW(768) & "m Kiê" & ChrW(769) & "m Shop", LookAt:=xlPart, SearchOrder:=xlByRows, _
MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False, _
FormulaVersion:=xlReplaceFormula2
Selection.AutoFilter
End Sub
所以我在代码之前插入了这段代码
Dim ws As Worksheet
For Each ws In Sheets
并插入更多prepend每个范围...
ws.Range("A7").Select
但它对我不起作用。那么有没有其他的方法来做到这一点?循环VBA的所有工作表在该工作簿中,除了"主表"
关于我的数据,它看起来像这样:
enter image description here
所以我想改变A7:A结束向下是值B4。-然后过滤,过滤列T,V每个值= 0,并删除它
- 替换一些名称,这是运行marco 1工作表后的最终结果:enter image description here
2条答案
按热度按时间lrpiutwd1#
这是我通常遍历所有工作表的方式,但有一个例外:
在ws上运行的代码可能类似于以下内容:
3bygqnnd2#
当然,这不是最干净和最好的解决方案(参见注解“避免选择....”),但请保持代码不变,为调用它创建一个sub,如下所示: