退出执行函数的循环,然后重新进入循环

时间:2017-04-25 15:43:11

标签: excel vba excel-vba

我有一个循环遍历目录中任何工作簿中的每个工作表并执行某些代码。我需要调整该代码,以便在完成每个工作表后,它会跳转到该工作簿中名为" Data"的工作表中的特定工作表。并从某个单元格复制数据。以下是我认为需要进行更改的代码片段:

    Set wkbkorigin = Workbooks.Open(ThisWorkbook.Path & "/" & Fname)
        For Each ws In wkbkorigin.Worksheets
        Select Case LCase(ws.Name)
        Case "admin", "man hrs", "tp cycle times", "data2", "ent_equipment_data", "starthere", "ltp trend", "cl trend", "pl trend", "data"
        'Do Nothing
        Case Else
        If ws.Range("B5").Value <> "" Then
        With ws
            RngDest.Cells(1, 1).Value = .Range("D3").Value
            RngDest.Cells(1, 2).Value = .Range("E9").Value
            RngDest.Cells(1, 5).Value = .Range("E10").Value
            RngDest.Cells(1, 8).Value = .Range("E21").Value
            RngDest.Cells(1, 11).Value = .Range("E22").Value
            RngDest.Cells(1, 14).Value = .Range("E29").Value
            RngDest.Cells(1, 17).Value = .Range("E30").Value
        End With
        End If
        End Select
        Set RngDest = RngDest.Offset(1, 0)

        Next
        wkbkorigin.Close SaveChanges:=False   'close current file

        Fname = Dir()     'get next file

我尝试在很多地方插入代码,但是由于某种原因它会跳过它或执行数据然后复制它。

0 个答案:

没有答案