小编Jul*_*i44的帖子

VBA 错误处理 GoTo Next Loop 而不是恢复

当导入选项卡中没有文件路径时,此代码会产生错误。因此,我包含On Error Resume Next为了运行下一个循环。但是,在On Error Resume Next代码继续运行复制操作之后,这弄乱了我要复制到的选项卡。

我发现解决方案是 On Error 代码应该进入下一个循环而不是继续操作。有没有人对如何更改错误处理有任何意见?

Sub ImportBS()

Dim filePath As String
Dim SourceWb As Workbook
Dim TargetWb As Workbook
Dim Cell As Range
Dim i As Integer
Dim k As Integer
Dim Lastrow As Long


'SourceWb - Workbook were data is copied from
'TargetWb - Workbook were data is copied to and links are stored

Application.ScreenUpdating = False

Set TargetWb = Application.Workbooks("APC Refi Tracker.xlsb")
Lastrow = TargetWb.Sheets("Import").Range("F100").End(xlUp).Row - 6


    For …
Run Code Online (Sandbox Code Playgroud)

error-handling excel vba

3
推荐指数
1
解决办法
121
查看次数

标签 统计

error-handling ×1

excel ×1

vba ×1