Selecting a Cell & Range

KNKN9

Board Regular
Hi and Thanks in advanced.

I am trying to select the cell P10 and the last col as set as my range below.
but I receive the error 'Application defined - object error'
I have the code below:

Code:
Sub time_trans()Dim last_col As Range
Set last_col = ActiveWorkbook.ActiveSheet.Range("p10").End(xlToRight).Offset(-1, 0)
Range("P10:P" & last_col).Select
Thanks.
 

Rick Rothstein

MrExcel MVP
Hi and Thanks in advanced.

I am trying to select the cell P10 and the last col as set as my range below.
but I receive the error 'Application defined - object error'
I have the code below:

Code:
Sub time_trans()Dim last_col As Range
Set last_col = ActiveWorkbook.ActiveSheet.Range("p10").End(xlToRight).Offset(-1, 0)
Range("P10:P" & last_col).Select
The last_col variable is a Range... you cannot concatenate a range onto a text string. On top of that, you are trying to use last_col in the row location for the range. Try it like this instead...

Range("P10", last_col).Select
 

Fluff

MrExcel MVP, Moderator
How about
Code:
Sub time_trans()

Dim last_col As Long
last_col = ActiveWorkbook.ActiveSheet.Range("p10").End(xlToRight).Column
Range("P10", Cells(10, last_col)).Select
End Sub
 

Fluff

MrExcel MVP, Moderator
Are you referring to Rick's solution, or mine?
 

Fluff

MrExcel MVP, Moderator
Which line gives the error?
With your code I get a "Range of object Global failed" error, rather than the "Application defined - object error" you are reporting.
 

KNKN9

Board Regular
I receive the error with this code

Code:
[COLOR=#333333]Range("P10", Cells(10, last_col)).Select
[/COLOR]
Which line gives the error?

With your code I get a "Range of object Global failed" error, rather than the "Application defined - object error" you are reporting.
 

Fluff

MrExcel MVP, Moderator
Is the sheet protected?
Also do you have any merged cells?
 

Some videos you may like

This Week's Hot Topics

Top