excel - Excel 宏脚本停止工作,运行时显示忙碌的鼠标图标,但对电子表格没有任何作用
问题描述
我正在使用这个宏来清理节目标题并将季节和剧集编号排序到他们自己的列中。效果很好!
我已经有大约 6 个月没有运行它了,现在当我打开电子表格并尝试运行它时,它只是以一个忙碌的圆圈旋转。
我完全不知道什么会导致这个宏不起作用。自从我上次运行它以来,我没有对代码进行任何更改并且它确实有效。
Excel 2016
我已经检查了参考资料,并且相当确定我已经包含了所有必要的参考资料。
参考资料:https ://i.imgur.com/m4YCGAP.png
我尝试单步执行 (F8) 宏以找出问题所在,但似乎没有一个宏在运行,尽管它正在运行。
Sub cleanTitles()
Dim strTitle As String, regEx As New RegExp, strPattern As String
Dim strSeason As String, strEpisode As String, strYear As String
With regEx
.Global = True
Dim j As Integer: j = 2
While Not Range("A" & j).Value = vbNullString
If Range("F" & j).Value = vbNullString Then
strTitle = Range("A" & j).Value
.Pattern = "[Ss]\s?(\d{1,2})[xX\s]?[Ee]\s?(\d{1,2}).*"
Set Matches = .Execute(strTitle)
If Matches.Count = 0 Then
.Pattern = "[\W_ ](\d{1,2})\s?[xX]\s?(\d{1,2}).*"
Set Matches = .Execute(strTitle)
End If
If Matches.Count = 0 Then
Range("F" & j) = vbNullString
Range("G" & j) = vbNullString
Else
strSeason = Matches(0).SubMatches(0)
strEpisode = Matches(0).SubMatches(1)
Range("F" & j) = strSeason
Range("G" & j) = strEpisode
strTitle = .Replace(strTitle, vbNullString)
End If
.Global = True
.Pattern = "\{[^\}]*\}[\W_]?"
Set Matches = .Execute(strTitle)
If Matches.Count <> 0 Then
strTitle = .Replace(strTitle, vbNullString)
End If
.Pattern = "\[[^\]]*\][\W_]?"
Set Matches = .Execute(strTitle)
If Matches.Count <> 0 Then
strTitle = .Replace(strTitle, vbNullString)
End If
.Pattern = "\([^\)]*\)[\W_]?"
Set Matches = .Execute(strTitle)
If Matches.Count <> 0 Then
strTitle = .Replace(strTitle, vbNullString)
End If
.Global = False
.Pattern = "[\W_](\d{4}).*"
Set Matches = .Execute(strTitle)
If Matches.Count <> 0 Then
strYear = Matches(0).SubMatches(0)
If strYear <= "1920" Then
Range("F" & j) = Left(strYear, 2)
Range("G" & j) = Right(strYear, 2)
End If
strTitle = .Replace(strTitle, vbNullString)
End If
.Pattern = "(\d{4})$"
Set Matches = .Execute(strTitle)
If Matches.Count <> 0 Then
strTitle = .Replace(strTitle, vbNullString)
End If
.Pattern = "^\d+-?([a-zA-Z])"
Set Matches = .Execute(strTitle)
If Matches.Count <> 0 Then
strTitle = .Replace(strTitle, Matches(0).SubMatches(0))
End If
.Global = True
.Pattern = "([a-z0-9])([A-Z])"
Set Matches = .Execute(strTitle)
strTitle = .Replace(strTitle, "$1" & " " & "$2")
.Pattern = "([a-zA-Z])([0-9])"
Set Matches = .Execute(strTitle)
strTitle = .Replace(strTitle, "$1" & " " & "$2")
.Global = False
Range("A" & j) = IIf(strTitle <> vbNullString, strTitle, ".")
End If
j = j + 1
Wend
End With
End Sub
--- 要清理的示例节目标题 ---生活
大爆炸第 10 季第 15 集:运动混响生活
大爆炸第 10 季第 16 集:津贴蒸发
100 第 3 季第 2 集:万和达:第二部分 生活
大爆炸理论第10季第19集:合作波动
第100季第3季第3集:你进入这里
的好医生第1季第12集:岛屿第二部分
该宏应该从A列中删除诸如“Season”或“Episode”之类的文本,然后将相应的数字添加到F和G列
中。它还应该删除诸如“:”之类的标点符号
示例结果,忽略未突出显示的列https://i.imgur.com/deTNHBs.png
解决方案
推荐阅读
- reactjs - 为什么我的应用程序无法处理表单的单选按钮选定值?
- python - 在 python3 manage.py run server 中运行我的 django 项目时,我收到此错误 ModuleNotFoundError: No module named 'pip._vendor.urllib3.connection'
- ios - 如何通过推送通知 IOS 查看我的通知?
- google-analytics - Google Analitics Reporting API V4 batchGet 方法需要 viewId,但如何找到呢?
- json - 使用 OnEventActivity 过滤事件
- powerapps - 选择和查找表的 PowerApp 问题
- mysql - phpMyAdmin/Plesk 中与服务器的连接的字符集/排序规则
- c# - 有没有办法在 C# 中设置进程的 mainWindowTitle,除了 user32.dll?
- python - 使用 Python 与 Spotify 和 Genius API 抓取歌词。100首歌曲后停止?
- azure - 使用 http 在现有 Function App 中添加/删除 Azure 函数