0

I'm having the error "runtime error 1004 method range of object _global failed" when I launched the following macro :

Dim nameDebut As Range, nameFin As Range ' <- my global variable
sub mySub()
...
   Set nameDebut = Range("A1").Offset(0, 1)
   Set nameFin = Range("A1").Offset(0, 20)
   Range("nameDebut:nameFin").Select ' <- fail occurs here
...

So I would like to select this range of cells like this. Is it possible ? Any workaround ?

Tx

1 Answer 1

1

Just change the last line to

Range(nameDebut,nameFin).Select 

Not discussing your code, but using select is nearly never needed in VBA. Maybe this can help:

dim myRange as Range
set myRange = Range(nameDebut,nameFin)
' Now use `myRange` for whatever you want to do...
Sign up to request clarification or add additional context in comments.

2 Comments

Does it work with that Select on the end? Shouldn't it just be set myRange = Range(nameDebut,nameFin) .... remembering to fully qualify the range reference as well.
For more detail on avoiding Select, see stackoverflow.com/questions/10714251/…

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.