2
我有这个函数根据左侧单元格的值更新单元格。 不幸的是,我不得不在函数结束之前添加最后一行代码,这样工作表就会回滚,因为当我点击按钮来运行宏时,每个单元格都会被选中,从而向下滚动到最后一行数据(600行)。如何停止Excel中的单元格滚动vba
如果你能告诉我该怎么做才能避免这种情况,那将非常感激。
的代码是:
Sub Button2_Click()
Dim regExM As New RegExp
Dim regEx As New RegExp
Dim matches, level
regExM.Pattern = "(M)(\d)"
regEx.Pattern = "[^-](.{0})(\d)"
regExM.Global = False
Range("J2").Activate
' Set Do loop to stop when an empty cell is reached.
Do Until IsEmpty(ActiveCell)
If regExM.Test(ActiveCell.Value) Then
Set matches = regExM.Execute(ActiveCell.Value)
For Each Match In matches
level = matches(0).SubMatches(1) + 3
ActiveCell.Offset(0, 1).Value = level
Next
ElseIf regEx.Test(ActiveCell.Value) Then
Set matches = regEx.Execute(ActiveCell.Value)
For Each Match In matches
level = matches(0).SubMatches(1)
ActiveCell.Offset(0, 1).Value = level
Next
End If
' Step down 1 row from present location.
ActiveCell.Offset(1, 0).Activate
Loop
Range("A1").Select
End Sub
谢谢
谢谢你,我会用你的解决方案,但我也从前面的招贴画的反应中学到了一些东西。 – Crouzilles