gpt4 book ai didi

vba - 如何在Excel VBA中停止单元格滚动

转载 作者:行者123 更新时间:2023-12-02 14:48:04 24 4
gpt4 key购买 nike

我有这个函数,可以根据左侧单元格的值更新单元格。不幸的是,我必须在函数结束之前添加最后一行代码,以便当我单击按钮运行宏时,工作表会向上滚动,每个单元格都会被选中,这使其向下滚动到最后一行数据(600 行)。

如果您能告诉我如何避免这种情况,我将不胜感激。

代码是:

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

谢谢

最佳答案

您可以在宏运行时关闭屏幕更新。

Sub Button2_Click()
Application.ScreenUpdating = False
'...code
Range("A1").Select
Application.ScreenUpdating = True
End Sub

关于vba - 如何在Excel VBA中停止单元格滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17448378/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com