如何避免一个子中出现重复的暗淡?

时间:2019-07-02 22:20:27

标签: excel vba

所以我基本上有这个报告A。我想复制所有报告B并将其粘贴到报告A的末尾,但这给了我这个重复的暗淡错误,我不知道如何区分它。我认识到重复项,但是我希望vba程序读取我的报告A excel文件(如果ws.Name像“ A *”,然后ws.Activate)并激活它,但是忽略A后面的数字,因为文件名不断变化。如果还有另一种方法可以做到这一点。这将是我整天试图找出的绝佳帮助。

Sub CopyBdata_into_Adata()
Dim ws As Worksheet
For Each ws In Worksheets
If ws.Name Like "B*" Then
ws.Activate   
Exit Sub    
End If

Next ws
Rows("1:1").Select    
Selection.Delete Shift:=xlUp    
Range("A2:BG3").Select    
Range(Selection, Selection.End(xlDown)).Select    
Selection.Copy 

Dim ws As Worksheet    
For Each ws In Worksheets    
If ws.Name Like "A*" Then    
ws.Activate    
Exit Sub    
End If    
Next ws

ActiveWindow.ScrollRow = 20    
ActiveWindow.ScrollRow = 120    
ActiveWindow.ScrollRow = 259    
ActiveWindow.ScrollRow = 318    
ActiveWindow.ScrollRow = 1251    
ActiveWindow.ScrollRow = 1867    
ActiveWindow.ScrollRow = 2462    
ActiveWindow.ScrollRow = 4348    
ActiveWindow.ScrollRow = 5162    
ActiveWindow.ScrollRow = 6571    
ActiveWindow.ScrollRow = 6948    
ActiveWindow.ScrollRow = 7604    
ActiveWindow.ScrollRow = 7921    
ActiveWindow.ScrollRow = 8080    
ActiveWindow.ScrollRow = 8437    
ActiveWindow.ScrollRow = 8576    
ActiveWindow.ScrollRow = 9092    
ActiveWindow.ScrollRow = 9211    
ActiveWindow.ScrollRow = 9648    
ActiveWindow.ScrollRow = 9886    
ActiveWindow.ScrollRow = 10244    
ActiveWindow.ScrollRow = 10561    
ActiveWindow.ScrollRow = 11177    
ActiveWindow.ScrollRow = 11514    
ActiveWindow.ScrollRow = 12090    
ActiveWindow.ScrollRow = 12308    
ActiveWindow.ScrollRow = 12487    
ActiveWindow.ScrollRow = 13122    
ActiveWindow.ScrollRow = 13241    
ActiveWindow.ScrollRow = 13579    
ActiveWindow.ScrollRow = 13599    
ActiveWindow.ScrollRow = 13757    
ActiveWindow.ScrollRow = 13797    
ActiveWindow.ScrollRow = 13817    
ActiveWindow.ScrollRow = 13936    
ActiveWindow.ScrollRow = 13996    
ActiveWindow.ScrollRow = 14015    
ActiveWindow.ScrollRow = 14174    
ActiveWindow.ScrollRow = 14194    
ActiveWindow.ScrollRow = 14274    
ActiveWindow.ScrollRow = 14393    
ActiveWindow.ScrollRow = 14512    
ActiveWindow.ScrollRow = 14532    
ActiveWindow.ScrollRow = 14690    
ActiveWindow.ScrollRow = 14710    
ActiveWindow.ScrollRow = 14750    
ActiveWindow.ScrollRow = 14810    
ActiveWindow.ScrollRow = 14829    
ActiveWindow.ScrollRow = 14849    
ActiveWindow.ScrollRow = 14869    
ActiveWindow.ScrollRow = 14909    
ActiveWindow.ScrollRow = 14929    
ActiveWindow.ScrollRow = 14949    
ActiveWindow.SmallScroll Down:=3

Range("A14988").Select    
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _    
:=False, Transpose:=False

Windows("Report_Instructions_and_macros_Test1.xlsm").Activate

End Sub

1 个答案:

答案 0 :(得分:0)

只需删除第二个

将ws作为工作表

声明。对于vba中的循环控制变量,您只需要在子函数或函数中将其变暗一次即可。