Range - Application Defined or Object Defined Error

  • Thread starter Thread starter Dyl
  • Start date Start date
D

Dyl

Hello,

I am having a problem with declaring a range object. The code which I
receive the Application/Object Defined error for is

Set myRange2 =
ThisWorkbook.Worksheets("Procedures").Range(Cells(TotalNames + 3, 1),
Cells(TotalNames + 3, 2))

I am frustrated because I have a line of code in my program which does
work and is almost identical.

Set myRange = ThisWorkbook.Worksheets("Procedures").Range(Cells(2,
NumberofBuilds + 2), Cells(3, NumberofBuilds + 2))



I am unclear of how to use Range syntax, but I am comfortable referring
to cells using cell index numbers. Any help or reccomendations would
be appreciated.

Thanks for your time.

Dylan H
 
Should work, but what is the value of TotalNames?
Note that if your calculated range goes beyond the row/column limitations of
an Excel spreadsheet it will be unable to evaluate the range and you will get
the error you describe. Limits are 65,536 rows by 256 columns. So if
TotalNames is, say, 65535 then Cells(TotalNames + 3, 1) is out of bounds.
 
Hello Dylan,

You probably forgot to dimesion Range2 as either an Object type or
Range type.
Check that in your Sub or Function that there is a line like either of
the 2 shown...

Dim Range2 As Object
Dim Range2 As Range

Sincerely,
Leith Ross
 
It could be a problem with the resolution of cells. You do not specify the
worksheet when you make the reference. Try something like this...

with ThisWorkbook.Worksheets("Procedures").
Set myRange2 = .Range(.Cells(TotalNames + 3, 1), .Cells(TotalNames + 3, 2))
end with
 
Just for reference Cells would have been looking at the acitve sheet
(whatever that might be). Unless otherwise specified that is where it looks.
 
Back
Top