VBA代码仅在单步执行时有效

时间:2018-04-11 17:31:17

标签: excel vba excel-vba

代码仅在单步执行时有效。有任何想法吗?我查看了其他问题,但答案似乎是基于代码。谢谢!

参见代码:

Sub CopyPasteFilteredData()

    ActiveSheet.Range("$C$1:$BJ$15").AutoFilter Field:=4, Criteria1:="<>" 'selects all cells in range
    Range("C2").Select 'first cell of data
    Range(Selection, Selection.End(xlDown)).Select  'control down
    Range(Selection, Selection.End(xlToRight)).Select  'control right
    Selection.Copy    ' copy selection
    Sheets("Results Sheet").Select    'select results sheet
    Range("A2").Select
    Range("A" & Rows.Count).End(xlUp).Offset(1).Select     'select next available row
    ActiveSheet.Paste           'paste data
    Sheets("Stand Alone").Select             'move back to stand alone sheet
    ActiveSheet.ShowAllData                  'and unfilter all data
End Sub


Sub LoopCopyPaste()

Dim rng As Range
Dim cell As Range

Dim oldfilestring As String    'old file
Dim filestring As String       'new file

Set rng = Range("Files")       'set range based on file names

oldfilestring = "File A.xlsm"    

For Each cell In rng
    filestring = cell.Value
    ActiveWorkbook.ChangeLink Name:=oldfilestring, NewName:=filestring, Type:=xlExcelLinks    
CopyPasteFilteredData                    
    oldfilestring = filestring           
Next cell

End Sub

这循环遍历命名范围“文件” - 并将数据粘贴到结果表。

0 个答案:

没有答案