Selecting a Cell & Range

KNKN9

Board Regular
Joined
Mar 27, 2017
Messages
92
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
Joined
Apr 18, 2011
Messages
35,573
Office Version
2010
Platform
Windows
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
Joined
Jun 12, 2014
Messages
33,882
Office Version
365
Platform
Windows
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
 

KNKN9

Board Regular
Joined
Mar 27, 2017
Messages
92
Thank you for your response.
I still receive the same error message
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
33,882
Office Version
365
Platform
Windows
Are you referring to Rick's solution, or mine?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
33,882
Office Version
365
Platform
Windows
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
Joined
Mar 27, 2017
Messages
92
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
Joined
Jun 12, 2014
Messages
33,882
Office Version
365
Platform
Windows
Is the sheet protected?
Also do you have any merged cells?
 

Forum statistics

Threads
1,085,882
Messages
5,386,544
Members
402,004
Latest member
moneyman4438

Some videos you may like

This Week's Hot Topics

Top