在尝试测试某些代码时,我遇到了一个我以前不记得遇到的问题。当我遍历代码时,它在ClearContents行之后停止......没有错误,没有警告,没有任何内容。Excel VBA调试程序停止时没有错误或警告
Public Sub CreateCurMth(wsCur As Worksheet)
Dim iData As Integer, iRow As Integer
Dim wbData As Workbook
On Error GoTo err_here
iRow = wsCur.Cells(Rows.Count, 1).End(xlUp).Row
wsCur.Range("A10:X" & iRow).ClearContents '<----- Fails after this line
'Assume that file is already open
Set wbData = Workbooks("qReport.xlsx")
... etc
err_here:
Beep
End Sub
wsCur是在调用子中分配的工作表。代码准确地返回iRow作为wsCur上最后一次使用的行。此外,内容被清除......以便该行执行正常。死亡后没有发出哔声。我也有一个关于嘟嘟的断点,它从来没有被击中。
因此,正如我在输入问题时经常发生的那样......我一直在尝试一些事情,通常最终会在尝试完全记录我的问题时找到我的答案。这次没有半结果的结果...没有理由,我可以找到,上面的代码现在正在工作......但是,我在VBA的其他部分中保持与上面部分不相似的相同问题。我一直在研究这个项目一个星期左右,以及今天之前的所有测试,这个代码已经工作......或者至少像通常预期的那样出错。
每次调试器停止时,都没有错误,也没有警告。失败的线条甚至没有任何共同之处。所以我只能假设这是我的系统环境。
我搜索了谷歌搜索,并没有答案。我希望有人在这之前已经解决了这个问题,或者至少可以让我指出正确的方向。
我的代码编译没有错误。这是当前停止的行:
wsTemp.Delete
临时工作表被删除...然后暂停。
编辑:好吧,所以我认为这只是一个损坏的Excel文件,并做了一个打开&修复解决了几个小时。但现在我在这里调试失败后
wsTemp.Delete
我打开工具>选项>常规>打破所有的错误,我仍然没有错误,没有报警...代码迈通一样的问题暂停。
只是要彻底...这里是整个过程到故障点:
'Creates combined joblist from last and current month
Sub CreateCompareList(wsCur As Worksheet, wsLast As Worksheet, wsComp As Worksheet)
Dim wsTemp As Worksheet
Dim lLastRow As Long, lCurRow As Long, lLMRow As Long
Dim iCol As Integer, x As Integer
wsComp.Unprotect SheetPwd
lLastRow = wsComp.Cells(Rows.Count, 27).End(xlUp).Row 'Get the last row
If lLastRow = 9 Then
'No data on sheet - Don't ruin headers
Else
wsComp.Rows("10:" & lLastRow).ClearContents 'Clear that section of Job names and numbers
End If
Set wsTemp = Worksheets.Add 'Add a Temp Sheet to filter jobs
lCurRow = wsCur.[A10].End(xlDown).Row 'Get the last row
wsCur.Range("A10:B" & lCurRow).Copy 'Grab all jobs for the current month
wsTemp.[A1].PasteSpecial 'Paste job list from Current Month
Application.CutCopyMode = False
lLMRow = wsLast.[A10].End(xlDown).Row 'Get the last row
wsLast.Range("A10:B" & lLMRow).Copy 'Grab all jobs from the Last month
lLastRow = wsTemp.[A1].End(xlDown).Row 'Get the last row
wsTemp.Cells(lLastRow + 1, 1).PasteSpecial 'Paste jobs from last month below jobs from current month
Application.CutCopyMode = False
lLastRow = wsTemp.[A1].End(xlDown).Row 'Get new last row
'Filter out duplicates based on the JobNo
wsTemp.Range("$A$1:$B$" & lLastRow).RemoveDuplicates Columns:=2, Header:=xlNo
lLastRow = wsTemp.[A1].End(xlDown).Row 'Get new last row
wsTemp.Range("A1:B" & lLastRow).Copy 'Copy unique Jobs
wsComp.[A10].PasteSpecial 'Paste Unique Jobs to Compare sheet
'Clean up Temp sheet
' Application.DisplayAlerts = False
wsTemp.Delete
我已经与DisplayAlerts开启和关闭,当警报是......我得试了一下在表单上可能存在数据的提示...我单击删除,工作表被删除...然后代码暂停。它偶尔会在其他.ClearContents行上出现类似上面的问题。
我不明白你的意思是“在此行后失败”。这听起来不像是失败了,它只是没有达到你的期望。没有错误,对吧? – Kyle
没有错误。调试器也暂停,并且不再运行代码。它结束的行不是代码的最后一行。你是对的,它没有达到我期望的水平......我希望在那条线上按F8可以做任何线条应该做的事情,然后将高亮部分移动到下一行并继续......或者出错并且让我知道刚刚发生的事情。 – Rdster
这是你的全文是什么? – Kyle