Method 'Range' of object'_Worksheet' failed

  • This code is being run on "Sheet1".


    Code
    Set rng1 = Range(Sheets("Sheet2").Cells(4, 1), Sheets("Sheet2").Cells(28, 1))


    Error:

    Quote

    "Method 'Range' of object'_Worksheet' failed"

  • Re: Method 'Range' of object'_Worksheet' failed


    1

    Code
    Set rng1 = Sheets("sheet2").Range(Sheets("Sheet2").Cells(4, 1), Sheets("Sheet2").Cells(28, 1))


    2

    Code
    With Sheets("sheet2")
            Set rng1 = .Range(.Cells(4, 1), .Cells(28, 1))
        End With
  • Re: Method 'Range' of object'_Worksheet' failed


    If you use "Range()" without qualifying it with a worksheet object it will refer to the ActiveSheet. So you're existing code is saying "I want to use a range on this sheet, that is made up of cells on another sheet" which obviously doesn't make sense and so the code fails.


    You'll notice that jindon's code uses the sheet object to qualify the ranges which is why it works. :)

  • Re: Method 'Range' of object'_Worksheet' failed


    Still get an error. Sheets "Sheet1" and "Sheet2" exist.


    Code
    Set rng1 = Sheets("Sheet1").Range(Sheets("Sheet2").Cells(4, 1), Sheets("Sheet2).Cells(28, 1))


    Error:
    "Application-defined or object-defined error"

  • Re: Method 'Range' of object'_Worksheet' failed


    Quote

    Set rng1 = Sheets("Sheet1").Range(Sheets("Sheet2").Cells(4, 1), Sheets("Sheet2).Cells(28, 1))


    You're still trying to create a range on sheet 1, with cells from sheet 2 - that doesn't make sense. What are you actually trying to do? Adding some context may help here.

  • Re: Method 'Range' of object'_Worksheet' failed


    Here is the whole thing. the chart objects: "XValue" and "Value" are where the errors are.


Participate now!

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