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.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
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
 
Upvote 0
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
 
Upvote 0
Are you referring to Rick's solution, or mine?
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0
Is the sheet protected?
Also do you have any merged cells?
 
Upvote 0

Forum statistics

Threads
1,214,793
Messages
6,121,614
Members
449,039
Latest member
Mbone Mathonsi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top