Error 1004 in range definition

  • Good morning,
    I'm using Excel 2010. In a subroutine that has always worked well in other programs, it now appears an error message 1004 in the definition of a range
    Example:


    Code
    With Worksheets(Ws$)
    Debug.Print .Cells(5, 3).Value                          'OK
    Debug.Print .Range("C5").Value                   'OK
    Debug.Print .Range(.Cells(5, 3)).Value 'Error 1004
    End With


    I do not understand. Any idea?
    Thanks for your helping

  • Re: Error 1004 in range definition


    The default property for a range is its value, so your original line was passing the value of the cells to the Range property. Qualify it with the .ADDRESS property...


    Code
    Debug.Print .Range(.Cells(5, 3).Address).Value ' No Error 1004
  • Re: Error 1004 in range definition


    Yes, it works very well.
    At this point, however, I have two programs that use the same subroutine and the same worksheets.
    It would be nice to understand why the first program works without . Address and here I must insert . Address
    Greetings and thanks

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!