vba - VBA 模块似乎无缘无故停止。
问题描述
我有这个 VBA 代码,它在大 for 循环之后结束,在“msgbox”h”之前。msgbox 是为了检查它是否继续。代码通过循环运行,但仅此而已。有人可以帮我理解为什么吗?
Sub countPT()
'Select file
Application.ScreenUpdating = False
Dim i As Integer, lastRow As Integer, tellerPoE(13) As Integer,
telleruPoE(13) As Integer, SwitchInd As Integer
Dim wb As Workbook, wb2 As Workbook
Dim krrom As String, Comment As String
For i = 1 To 13
tellerPoE(i) = 0
telleruPoE(i) = 0
Next i
Set wb = ActiveWorkbook
openFile = Application.GetOpenFilename("Excel-files,*.xls*", 1, _
"Select a file to open", , False)
Application.ScreenUpdating = False
If Len(openFile) = 0 Then
MsgBox "No file selected.", vbExclamation, "Sorry!"
End
End If
Workbooks.Open openFile
Set wb2 = ActiveWorkbook
'Read through and count -> put to array on index
lastRow = wb2.Worksheets("Rådata").Range("F" & Rows.Count).End(xlUp).Row
For i = 114 To lastRow
wb2.Activate
If CStr(wb2.Worksheets("Rådata").Cells(i, "G")) = "528" Then
krrom = CStr(wb2.Worksheets("Rådata").Cells(i, "F"))
SwitchInd = SwitchCode(krrom)
'If SwitchInd = 0 Then
'GoTo ContinueLoop
'End If
Comment = LCase(CStr(wb2.Worksheets("Rådata").Cells(i, "M")))
If (InStr(Comment, "poe") Or InStr(Comment, "kamera") Or
InStr(Comment, "cam")) Then
If Len(wb2.Worksheets("Rådata").Cells(i, "L").Value) > 0 Then
tellerPoE(SwitchInd) = tellerPoE(SwitchInd) + 1
End If
tellerPoE(SwitchInd) = tellerPoE(SwitchInd) + 1
Else
If Len(wb2.Worksheets("Rådata").Cells(i, "L").Value) > 0 Then
telleruPoE(SwitchInd) = telleruPoE(SwitchInd) + 1
End If
telleruPoE(SwitchInd) = telleruPoE(SwitchInd) + 1
End If
'ContinueLoop
End If
Next i
'Check up to existing
'Update values
'Give message on change
MsgBox "h"
For j = 1 To 13
If tellerPoE(j) > CInt(Cells(5 + j, "E")) * 2 Or telleruPoE(j) >
CInt(Cells(5 + j, "G")) Then
Cells(6 + j, "K") = "Punkter økt"
End If
Cells(5 + j, "E") = tellerPoE(j)
Cells(5 + j, "G") = telleruPoE(j)
Next j
'Empty and close
Application.CutCopyMode = False
Set wb = ActiveWorkbook
wb2.Close
Application.ScreenUpdating = True
End Sub
一些代码被注释掉以尝试解决问题或更容易找到块
解决方案
之后MsgBox
,删除循环并编写以下内容:
MsgBox "h"
For j = 1 To 13
Cells(6 + j, "K") = "Punkter økt"
Next j
检查它是否产生你需要的东西。如果是这样,那么它会起作用并且您的情况是错误的。
推荐阅读
- javascript - 如何在 angularjs 中创建输入格式属性指令?
- laravel - laravel vue 插件使用方法
- ios - 应用程序的更新版本未反映在设置的应用程序列表中,但应用程序正在更新
- node.js - 使用 express-validator 自定义验证器验证两个字段
- eiffel - Eiffel:“埃菲尔”库和图案库有什么区别?
- c# - 无法将 Process.StartInfo.WorkingDirectory 设置为从 c# 调用 exe
- vb.net - 如何检查 Tesseract 是否已完成文件处理?
- css - 是否有选择器来禁用块内的引导程序?
- c# - 从 XML C# 中取出项目并执行批量删除
- python-3.x - 创建显示来自烧瓶 sqlalchemy 占位符的动态内容的 Bootstrap 可折叠手风琴表行