ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Range syntax (https://www.excelbanter.com/excel-programming/330286-range-syntax.html)

Dr.Schwartz

Range syntax
 
How come this piece of code does not work?

Dim Headers As Range
Set Headers = Range(Cells(ImNavigateRow - 1, 2), Cells(ImNavigateRow - 1,
2).End(xlToRight).Column)

I get an: Method 'Range' of object '_worksheet' failed error.

Can anyone correct this for me?
Thanks
The Doctor

K Dales[_2_]

Range syntax
 
Perhaps this is what you are trying to do?
Set Headers = Range(Cells(ImNavigateRow - 1, 2), Cells(ImNavigateRow - 1,
Cells(ImNavigateRow-1,2).End(xlToRight).Column))

"Dr.Schwartz" wrote:

How come this piece of code does not work?

Dim Headers As Range
Set Headers = Range(Cells(ImNavigateRow - 1, 2), Cells(ImNavigateRow - 1,
2).End(xlToRight).Column)

I get an: Method 'Range' of object '_worksheet' failed error.

Can anyone correct this for me?
Thanks
The Doctor


Norman Jones

Range syntax
 
Hi Dr. Schwartz,

Try:

Set Headers = Range(Cells(ImNavigateRow - 1, 2), _
Cells(ImNavigateRow - 1, 2).End(xlToRight))


---
Regards,
Norman



"Dr.Schwartz" wrote in message
...
How come this piece of code does not work?

Dim Headers As Range
Set Headers = Range(Cells(ImNavigateRow - 1, 2), Cells(ImNavigateRow - 1,
2).End(xlToRight).Column)

I get an: Method 'Range' of object '_worksheet' failed error.

Can anyone correct this for me?
Thanks
The Doctor




Dr.Schwartz

Range syntax
 
Yes thank you it works, but I think I'm going to use Norman's solution (is't
shorter)

"K Dales" wrote:

Perhaps this is what you are trying to do?
Set Headers = Range(Cells(ImNavigateRow - 1, 2), Cells(ImNavigateRow - 1,
Cells(ImNavigateRow-1,2).End(xlToRight).Column))

"Dr.Schwartz" wrote:

How come this piece of code does not work?

Dim Headers As Range
Set Headers = Range(Cells(ImNavigateRow - 1, 2), Cells(ImNavigateRow - 1,
2).End(xlToRight).Column)

I get an: Method 'Range' of object '_worksheet' failed error.

Can anyone correct this for me?
Thanks
The Doctor


Dr.Schwartz

Range syntax
 
As always (2 for 2) you deliver, thank you Norman.

"Norman Jones" wrote:

Hi Dr. Schwartz,

Try:

Set Headers = Range(Cells(ImNavigateRow - 1, 2), _
Cells(ImNavigateRow - 1, 2).End(xlToRight))


---
Regards,
Norman



"Dr.Schwartz" wrote in message
...
How come this piece of code does not work?

Dim Headers As Range
Set Headers = Range(Cells(ImNavigateRow - 1, 2), Cells(ImNavigateRow - 1,
2).End(xlToRight).Column)

I get an: Method 'Range' of object '_worksheet' failed error.

Can anyone correct this for me?
Thanks
The Doctor






All times are GMT +1. The time now is 05:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com