【发布时间】: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 无法解决问题,请尝试重建文件(或从您的一位用户那里获取工作副本)