Share via

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

Anonymous
2012-08-09T16:51:47+00:00

What am I doing wrong  here. The highlighted code line below is giving me a "Method 'Range' of object '_Worksheet' failed" error.

Dim UTws As Worksheet

Dim UTlRow As LongDim  countRange As String

Set UTws = Worksheets("Upload Tracker")

UTlCol = UTws.Cells(1, Columns.Count).End(xlToLeft).Column

countRange = .Range(Cells(10, 9), Cells(10, UTlCol)).Address

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2012-08-09T17:09:40+00:00

···

countRange = .Range(Cells(10, 9), Cells(10, UTlCol)).Address···

You might be suffering from Copy&Paste-itis. The .Range( property starts with a period (i.e. full stop). This is meant to be used inside a a With ... End With wrapper that tells it where its parent is. However, if you used one you would also have to insert a period before both of the Cells(.. properties in order that they know where their parents are.

As it sits, it should work if you change .Range(... to Range(... (without the period) as long as Worksheets("Upload Tracker") is the ActiveSheet. If you need the wrapper then try something like,

Dim UTws As Worksheet

Dim UTlRow As LongDim  countRange As String

Set UTws = Worksheets("Upload Tracker")

With UTws

    UTlCol = .Cells(1, Columns.Count).End(xlToLeft).Column

    countRange = .Range(.Cells(10, 9), .Cells(10, UTlCol)).Address

End With

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

Answer accepted by question author

Anonymous
2012-08-09T17:26:21+00:00

Thanks Jeeped, that seem to do the trick. Now I need to figure out how to get my range:

 countRange = .Range(.Cells(10, 9), .Cells(10, UTlCol)).Address

in the form

$I10:$P10

instead of

$I$10:$P$10.

UPdate:

found the answer.

countRange = .Range(.Cells(10, 9), .Cells(10, UTlCol)).Address(RowAbsolute:=False)

Thanks.

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful