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

  • Get External Data (long shot question!)
    This is likely a long shot but I am wondering if it is at all possible for Excel to somehow 'change' the contents of a URL that is being linked to...
  • Importing multiple excel files into one spreadsheet
    Hi, I'm trying to import multiple excel files (with the same format into a single spreadsheet) so that each day's file is listed underneath the...
  • Cell Formatting
    Good Morning, I need to format a few different cells in the following manners: A1 has to always add a colon (:) after whatever is typed in by a...
  • How to copy multiple rows using If
    Hi all, I'm very new to VBA and have written this simple code to copy certain cells if a certain cell within that row contains any data. I need...
  • Workbook_Change stopped working !
    I am working on an app to speed up & automate processing of Credit Cards statements. After data is input from a CSV file, it is presented to the...
  • VBA If statement
    Dear All, I have two dates, where I'd like a message box to pop, if the dates are between this criteria. [CODE] sDate1 = #10/1/2019#...
Top