View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jake Marx[_3_] Jake Marx[_3_] is offline
external usenet poster
 
Posts: 860
Default Help in using an Offset in a .Range().Select

Hi Robert,

A few problems with your code. First, you need to specify which worksheet
you're working with. Secondly, you should make sure your range references
are fully-qualified (easiest way is to use a With block). Here's some
modified code (untested) which should work:

With Worksheets("Sheet1")
.Range(.Range("A1"), .Range("A1").Offset(colTOright)).Select
End With

Even easier would be something like this:

Worksheets("Sheet1").Range("A1").Resize(ColumnSize :=colTOright +
1).Select

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


roblo wrote:
I am trying to Select a Range of cells where the last cell is
calcualted and will be plugged in at run time.

worksheets.Range("A1:C1").Select ' This works of course, selecting
A1 to C1 but I wanted the ending cell to be calculated.

worksheets.Range("A1", Range("A1").Offset(colTOright)).Select

Where colTOright will be calculated earlier. I tried just plugging in
a number for colTOright but get an VBScript runtime error, Type
mismatch: 'Range'

Is there another way?

Thanks
Robert