VBA – 与与select命令太慢。 如何更好地优化运行速度?

我正在select一个范围,并在With命令中使用这个select,正如你所知道的, .Selection命令将减慢这个过程。 有什么更好的方式来编写这个代码,运行速度更快?

这里是我的代码:

 Sheets(Currentsheetname).Range("A" & SelRowNumber + 1 & ":A" & lastrow).Select With .Selection.Validation .Delete .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _ xlBetween, Formula1:="Remove" .IgnoreBlank = True .InCellDropdown = True .InputTitle = "" .ErrorTitle = "Warning" .InputMessage = "" .ErrorMessage = "Please select a value from the list available in the selected cell." .ShowInput = True .ShowError = True End With 

这里是删除SelectSelection样子:

 With Sheets(Currentsheetname).Range("A" & SelRowNumber + 1 & ":A" & lastrow).Validation .Delete .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _ xlBetween, Formula1:="Remove" .IgnoreBlank = True .InCellDropdown = True .InputTitle = "" .ErrorTitle = "Warning" .InputMessage = "" .ErrorMessage = "Please select a value from the list available in the selected cell." .ShowInput = True .ShowError = True End With 

这是如何删除select和加快过程:

 With Sheets(Currentsheetname).Range("A" & SelRowNumber + 1 & ":A" & lastrow).Validation .Delete .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _ xlBetween, Formula1:="Remove" .IgnoreBlank = True .InCellDropdown = True .InputTitle = "" .ErrorTitle = "Warning" .InputMessage = "" .ErrorMessage = "Please select a value from the list available in the selected cell." .ShowInput = True .ShowError = True End With 

总是尽量避免VBA中的分拣和激活。