3

This problem is driving me crazy. I have the following code:

'unprotect sheet
If.Range("Start").Row+1<.Range("End").Row then
  .Rows(.Range("Start").Row+1 & ":" & .Range("End").Row-1).Select
  Selection.Delete Shift:=xlUp
  'protect sheet
End if

when I run it in debugging mode and trace the code, it works perfectly. But when run the code in a normal mode (not debugging) it gives me an error message as " select method of Range class failed" This errors happens in the line: .Rows(.Range("Start").Row +1 .... that is just after the IF statement. Any ideas? Please help.

1
  • 1
    Please use the Code Sample button ("1010 101") to reformat your question. It is very hard to read. Commented Aug 28, 2010 at 23:41

1 Answer 1

7

This error usually means you are trying to select a range that belongs to a non-active sheet.

You almost always don't need to select anything:

.Rows(.Range("Start").Row+1 & ":" & .Range("End").Row-1).Delete Shift:=xlUp
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect! It worked. So, what I did, whenever I select a range anywhere in the code, I activate the corresponding sheet first then I select. Thanks a lot! It was very helptul!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.