View Single Post
  #8   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

Thanks, Tom!

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

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


Tom Ogilvy wrote:
If he wants to expand to the right I would suggest the following
modification:

With worksheet
.Range(.Range("A1"), .Range("A1").Offset(0,colTOright)).Select
End With


"Jake Marx" wrote in message
...
Hi roblo,

I didn't realize you were automating Excel from VBScript. Your
original syntax was correct, as you have a worksheet object variable
declared:

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


Should be:

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


--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

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


roblo wrote:
Thanks Jake for the suggestion, but it does not work in my .VBS
script. Maybe in VBA?

colTOright = 6
' Create a new Excel workbook
set objXL = WScript.CreateObject("Excel.Application")
objXL.Visible = True
set workbook = objXL.Workbooks.Add
set worksheet = workbook.Worksheets("sheet1")
' worksheet.Range("A1:F1").Select
With Worksheet("Sheet1")
Range(.Range("A1"), .Range("A1").Offset(colTOright)).Select
End With

I'm just trying to replace the ending cell (F1) with a string or use
an Offset. Didn't think it would be that difficult.

newColumn = .Cells(A1).Offset(colTOright).Value
and replace F1 with newColumn, but that object doesn't except
strings.


worksheet.Range("A1:F1").Select

Robert