ExcelBanter

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

Ray Batig

Range help
 
I have a named range on a worksheet. The macro would add a new entry to the
next cell in the row. I can get this part OK. I have found an instance, say
when I first use the worksheet, when the named range is only 1 cell long
and the cell will be empty. Before I add a new column, I want to fill the
first cell if it is empty.

This is the code, however, I get an error message that the object doesn't
support this property. What do you suggest to fix this? Is there a better
way to do this?

row = Range ("MyRange").Cell(0,1).Row

If Range ("MyRange").Count = 1 And Range ("MyRange").Cell(0,1).Value = ""
Then

col = Range ("MyRange").Cell(0,1).Column
Else

col =
Worksheets("MySheet").Cells(row,256).End(xlToLeft) .Offset(0,1).Column
End If

Thanks in advance for your help!

Ray



Rob van Gelder[_4_]

Range help
 
Ray,

Instead of Range ("MyRange").Count
Try: Range("MyRange").Cells.Count

You could be confusing Offset with Cells.

Instead of .Cell(0,1)
Try: .Cells(1,1)


Rob


"Ray Batig" wrote in message
ink.net...
I have a named range on a worksheet. The macro would add a new entry to

the
next cell in the row. I can get this part OK. I have found an instance,

say
when I first use the worksheet, when the named range is only 1 cell long
and the cell will be empty. Before I add a new column, I want to fill the
first cell if it is empty.

This is the code, however, I get an error message that the object doesn't
support this property. What do you suggest to fix this? Is there a better
way to do this?

row = Range ("MyRange").Cell(0,1).Row

If Range ("MyRange").Count = 1 And Range ("MyRange").Cell(0,1).Value =

""
Then

col = Range ("MyRange").Cell(0,1).Column
Else

col =
Worksheets("MySheet").Cells(row,256).End(xlToLeft) .Offset(0,1).Column
End If

Thanks in advance for your help!

Ray





Ray Batig

Range help
 
Rob,

Thanks. I had to replace Cell with Cells in the first three lines. A little
bit of confusion was cleared up by your eyes.

Cheers
Rob van Gelder wrote in message
...
Ray,

Instead of Range ("MyRange").Count
Try: Range("MyRange").Cells.Count

You could be confusing Offset with Cells.

Instead of .Cell(0,1)
Try: .Cells(1,1)


Rob


"Ray Batig" wrote in message
ink.net...
I have a named range on a worksheet. The macro would add a new entry to

the
next cell in the row. I can get this part OK. I have found an instance,

say
when I first use the worksheet, when the named range is only 1 cell

long
and the cell will be empty. Before I add a new column, I want to fill

the
first cell if it is empty.

This is the code, however, I get an error message that the object

doesn't
support this property. What do you suggest to fix this? Is there a

better
way to do this?

row = Range ("MyRange").Cell(0,1).Row

If Range ("MyRange").Count = 1 And Range ("MyRange").Cell(0,1).Value =

""
Then

col = Range ("MyRange").Cell(0,1).Column
Else

col =
Worksheets("MySheet").Cells(row,256).End(xlToLeft) .Offset(0,1).Column
End If

Thanks in advance for your help!

Ray








All times are GMT +1. The time now is 10:00 AM.

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