本文介绍了宏运行缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello so I have this code here that copys a row containing drop downs in each cell,

但是在一张表中代码运行得很快,但在其他工作表上,宏需要永远。

but in one sheet the code runs quickly , but on other sheet the macro takes forever.

有任何建议吗?

Sub insertAddRows ()
'添加用户请求的行数

Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.Calculation = xlManual
QI 。选择
Dim numrows As Integer
Dim lastrow As Integer
numrows = Application.InputBox _
("输入要添加行的部件号的数量","插入行") )

On Error GoTo 0

Application.DisplayAlerts = True

lastrow = Application.WorksheetFunction.IfError(Application.WorksheetFunction.Match(" &#",Worksheets(" Quote Input")。Range(" A:A"),0)," NA")



工作表(曲ot;引用输入")。范围(" AddRow")。复制

工作表("引用输入")。范围(单元格(lastrow,1),单元格(lastrow + numrows - 1, 1))。EntireRow.Insert'Shift:= xlDown

工作表("引用输入")。范围(单元格(lastrow,1),单元格(lastrow + numrows - 1,1))。 EntireRow.Hidden = False

Application.CutCopyMode = False

'Application.SendKeys" {ESC}"
Application.Calculation = xlAutomatic
Application.ScreenUpdating = True

End Sub

Sub insertAddRows()' adds amount of rows requested by userApplication.ScreenUpdating = False Application.DisplayAlerts = False Application.Calculation = xlManualQI.SelectDim numrows As IntegerDim lastrow As Integer numrows = Application.InputBox _ ("Enter Amount of Part Numbers to add Rows", "Insert rows") On Error GoTo 0 Application.DisplayAlerts = True lastrow = Application.WorksheetFunction.IfError(Application.WorksheetFunction.Match("&#", Worksheets("Quote Input").Range("A:A"), 0), "NA") Worksheets("Quote Input").Range("AddRow").Copy Worksheets("Quote Input").Range(Cells(lastrow, 1), Cells(lastrow + numrows - 1, 1)).EntireRow.Insert 'Shift:=xlDown Worksheets("Quote Input").Range(Cells(lastrow, 1), Cells(lastrow + numrows - 1, 1)).EntireRow.Hidden = False Application.CutCopyMode = False 'Application.SendKeys "{ESC}" Application.Calculation = xlAutomatic Application.ScreenUpdating = TrueEnd Sub




推荐答案

尝试将此添加到顶部:

    Application.EnableEvents = False

    Application.EnableEvents = False

这个到底部

    Application.EnableEvents = True

    Application.EnableEvents = True

很难理解为什么使用这一行而不看工作簿本身:

It is hard to understand why you are using this line, without seeing the workbook itself:





这篇关于宏运行缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 08:48