Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default How to select multiple ranges in Excel with vbs

Hello

In the meantime I've found a solution:

objExcel.ScreenUpdating = False '* Do not update the screen

< do the selection on the other worksheet

objExcel.ScreenUpdating = True '* Update the screen again

Stefan


"Tom Ogilvy" wrote in message
...
No it is not possible, but as I said, you usually don't need to select.

--
Regards,
Tom Ogilvy

"Stefan Mueller" wrote in message
...
Great, .Union was what I was looking for the whole morning.

Therefore the following command does my requested selection:

objExcel.Union(objExcel.ActiveSheet.Range(objExcel .Cells(SelectionPart1_RowF
rom,
SelectionPart1_Column), objExcel.Cells(SelectionPart1_RowTo,
SelectionPart1_Column)),
objExcel.ActiveSheet.Range(objExcel.Cells(Selectio nPart2_RowFrom,
SelectionPart2_Column), objExcel.Cells(SelectionPart2_RowTo,
SelectionPart2_Column))).Select

Many thanks for your help.
Stefan


PS: Does anyone know if it's even possible to select a cell/range in a
not
active worksheet?
Today I'm doing
objExcel.Worksheets("My Worksheet 1").Activate
objExcel.Cells(1, 1).Select
objExcel.Worksheets("My Worksheet 2").Activate

But this is flickering. Therefore I'm looking for something like
objExcel.Worksheets("My Worksheet 1").Cells(1, 1).Select



"Leo Heuser" wrote in message
...
Stefan

One way.
Remember to set a reference to the
Excel object library from the VBA-editor in Word with
Tools References

'Leo Heuser, 19-4-2005
Dim objExcel As Excel.Application
Dim SelRange As Excel.Range
Dim MyBook As Excel.Workbook

Set objExcel = New Excel.Application
Set MyBook = objExcel.Workbooks.Add
objExcel.Visible = True

With MyBook.ActiveSheet
Set SelRange = objExcel.Union(.Range("A1:A10"), .Range("C2:C8"))
End With

SelRange.Value = 1234

Set objExcel = Nothing

End Sub

--
Best Regards
Leo Heuser

Followup to newsgroup only please.

"Stefan Mueller" skrev i en meddelelse
...
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













Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
select multiple ranges in formula dschanak Excel Discussion (Misc queries) 2 June 6th 07 04:53 PM
in charting, how do i select data ranges from multiple sheets, sa. michael Charts and Charting in Excel 1 March 6th 05 03:01 PM
select multiple cell ranges in "sumif" formula? Hitcoach Excel Worksheet Functions 1 January 16th 05 11:07 PM
Select instersection of two ranges Bert[_3_] Excel Programming 1 February 16th 04 05:01 PM
VBA-Select several ranges using variables waveracerr[_8_] Excel Programming 2 February 10th 04 11:12 PM


All times are GMT +1. The time now is 08:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"