Dim rng1 as Excel.Range
Dim rng2 as Excel.Range
Dim rng3 as Excel.Range
Dim sh1 as Excel.Worksheet
set sh1 = objExcel.Activesheet
set rng1 = sh1.Range(sh1.Cells(SelectionPart1_RowFrom, _
SelectionPart1_Column), she.Cells(SelectionPart1_RowTo, _
SelectionPart1_Column))
set rng2 = sh1.Range(sh1.Cells(SelectionPart2_RowFrom, _
SelectionPart2_Column), sh1.Cells(SelectionPart2_RowTo, _
SelectionPart2_Column))
set rng3 = ObjExcel.Union(rng1,rng2)
rng3.Select
of course there usually is no reason to select as you can just refer to the
ranges
--
Regards,
Tom Ogilvy
"Stefan Mueller" <seekware-remove-@yahoo.com> wrote in message
news:3ckd52F6o8mddU1@uni-berlin.de...
> 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(SelectionPart1_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
>
>
Bookmarks