0

I have found a error that I don't understand. In (A) statements, I have a error code 1004 - "the Select method of the Range Class failed". (B) statement is Ok. No error. Why can't I use Range("J5").Select with Worksheet object in the second time? I have a few statements between Select worksheet 1 and Select worksheet 2, but I don't believe they interfer.

Set wbDF = Workbooks.Add
wbDF.Worksheets(1).Range("H4").Select
wbDF.Worksheets(2).Range("J5").Select  '(A)

wbDF.Worksheets(2).Activate            '(B)
Range("J5").Select  
Community
  • 1
  • 1
Gera
  • 31
  • 1
  • 1
  • 7

1 Answers1

1

You have to Activate or Select the sheet for you to select a Range in that sheet.
So your example (A) doesn't work since Worksheet(2) is not the currently selected Sheet.
Refer to this post on how to avoid using Select.

Community
  • 1
  • 1
L42
  • 19,427
  • 11
  • 44
  • 68
  • 1
    I have avoided using select. Instead, I have used the command directly like in (A), for example: wbDF.Worksheets(2).Range("A8").value = 100.50 - so I hoped that the select command worked the same way. As we have seen, it works only like you said. – Gera Aug 18 '14 at 14:30