【问题标题】:VBA EXCEL Macro code execution interruption using a Column reorder ArrayVBA EXCEL宏代码执行中断使用列重新排序数组
【发布时间】:2019-09-19 23:45:57
【问题描述】:

我正在使用以下编码进行列重新排序

Dim search As Range
Dim cnt As Integer
Dim colOrdr As Variant
Dim indx As Integer

colOrdr = Array("fullDt", "branchName", "mediumDesc", "successInd", "accountNumber", "secondaryAccountNumber", "executingPartyName", "executingPartyNumber", "tranType", "currencyAmount", "cashAmount", "mechanism", "presenterName", "transactionDescription", "foreignCurAmt", "foreignCurrencyCd", "remitterName", "beneficiaryName", "countryFlow", "transactionReferenceNumber") 

cnt = 1


For indx = LBound(colOrdr) To UBound(colOrdr)
    Set search = Rows("1:1").Find(colOrdr(indx), LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False)
    If Not search Is Nothing Then
        If search.Column <> cnt Then
            search.EntireColumn.Cut
            Columns(cnt).Insert Shift:=xlToRight
            Application.CutCopyMode = False
        End If
    cnt = cnt + 1
    End If
Next indx

昨天运行良好,但是今天运行宏时,我得到了“代码执行已被中断”的提示屏幕。

如果我一直按继续,代码会运行并完成,如果我调试,它会转到这两行代码之一

Columns(cnt).Insert Shift:=xlToRight
Application.CutCopyMode = False

我有其他用户使用相同的宏没有问题,所以现在我不确定这是代码问题,还是 VBA/Excel (2016) 或个人笔记本电脑问题。

任何帮助将不胜感激。

尼克

【问题讨论】:

  • 听起来像是损坏的 Excel 文件。如果重新启动 Excel/重新启动 PC 无法解决问题,请尝试重建文件(或从您的一位用户那里获取工作副本)

标签: arrays excel vba


【解决方案1】:

例如,当使用“Control+Pause”组合键来停止代码的执行时,就会发生这种中断。

如果多次按下组合键,缓存将尝试停止执行相同的次数。

在循环之前或“Next”指令之前放置“DoEvents”函数可能会显示中断与您的代码无关。

最好的问候,

弗雷德

【讨论】:

    猜你喜欢
    • 2011-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-24
    • 1970-01-01
    相关资源
    最近更新 更多