View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Don Guillett[_4_] Don Guillett[_4_] is offline
external usenet poster
 
Posts: 2,337
Default How to select multiple ranges in Excel with vbs

this might be easier in vba
Range("a1:a10,h2:h8").Select

--
Don Guillett
SalesAid Software

"Stefan Mueller" wrote in message
...
The following vbs code opens Excel and selects the ranges A1-A10 and

C2-C8:
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Add
objExcel.Visible = True
objExcel.ActiveSheet.Range("A1:A10,C2:C8").Select

But how can I do such a selection with variables?

e.g.
SelectionPart1_Column = 1
SelectionPart1_RowFrom = 1
SelectionPart1_RowTo = 10

SelectionPart2_Column = 3
SelectionPart2_RowFrom = 2
SelectionPart2_RowTo = 8

The following command selects only the first part (A1-A10):
objExcel.ActiveSheet.Range(objExcel.Cells(Selectio nPart1_RowFrom,
SelectionPart1_Column), objExcel.Cells(SelectionPart1_RowTo,
SelectionPart1_Column)).Select

But how can I add to the already selected part 1 also part 2 (C2-C8)?

Any help is very appreciated
Stefan