VBA:代码返回到某一行开始,然后崩溃

时间:2017-12-12 15:50:56

标签: excel vba excel-vba

目标:使用简单的代码调出文档,然后将值复制到打开文档。

问题:在For循环中i = 23时,无论第23行中的值是什么,它都会中断。在调试模式下,excel在.value = .value语句处崩溃。在运行模式下它开始,打开关于打开一个新文件的对话框,有.OpenFilePath对话框出现 - 然后崩溃。

Sub Run()
Dim rowcounter As Integer, fecha As Date, dashboard As Workbook
If rowcounter < 1 Then rowcounter = 1
MsgBox ("Please choose file")
Set dashboard = Workbooks.Add
SecurityBookpath = Application.GetOpenFilename
SecurityBook = Dir(SecurityBookpath)
Ms1 = MsgBox(SecurityBook & " is that right?", vbYesNo)
On Error Resume Next
  Set isitopen = Workbooks(SecurityBook)
  If isitopen Is Nothing Then Set isitopen = Workbooks.Open(SecurityBookpath)
On Error GoTo 0
For i = 22 To     Workbooks(SecurityBook).Sheets(1).Range("B10000").End(xlUp).Row
fecha = Workbooks(SecurityBook).Sheets(1).Range("BV" & i).Value
If fecha <> #12:00:00 AM# And fecha < Date - 7 Then
        If Left(Workbooks(SecurityBook).Sheets(1).Range("M" & i).Value, 2) < 14 Or Left(Workbooks(SecurityBook).Sheets(1).Range("M" & i).Value, 2) > 6 Then
        Workbooks(dashboard.FullName).Sheets(1).Range("B" & rowcounter & ":CD" & rowcounter).Value = Workbooks(SecurityBook).Sheets(1).Range("B" & i & ":CD" & i).Value
        rowcounter = rowcounter + 1
    End If
End If
Next i

是否出现错误陈述?有什么东西我错过了吗?

注意:这不适用于Mac或Windows Excel 2016.

0 个答案:

没有答案
相关问题