1

I am selecting a range and using that selection inside the With Command and as you all know, the .Selection command is going to slow down the process. What is the better way to write this code, to run it faster?

Here goes my code:

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 
0

2 Answers 2

2

Here is what it looks like with Select and Selection removed:

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 
Sign up to request clarification or add additional context in comments.

Comments

2

This is how to remove the selection and to speed up the process:

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 

Always try to avoid seletction and activation in VBA.

1 Comment

You are missing with at the beginning.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.