Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 312
Default Array difference?

Hi. Was hoping someone could clarify something for me. What is the
difference between the following:

Dim arr1()
arr1 = Array("Sheet1", "Sheet2", "Sheet3")

Dim arr2 As Sheets
Set arr2 = Sheets(Array("Sheet1", "Sheet2", "Sheet3"))

I've been reading the message boards a lot lately, and have seen bopth
methods being used for creating arrays. I think one is set up as a
variable, but not sure. Anyway, they apparently differ in their use of
syntax, becasue I have tried meshing both styles into my code, and one style
works while the other does not.

Just a general clarification would be greatly appreciated, or even better a
link to a site that describes in detail the difference? Thanks a bunch!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Array difference?

The first is creating an array of strings, the second is creating a sheets
object using an array of strings to define the sheets. So the latter will be
an object of 3 sheets.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Steph" wrote in message
...
Hi. Was hoping someone could clarify something for me. What is the
difference between the following:

Dim arr1()
arr1 = Array("Sheet1", "Sheet2", "Sheet3")

Dim arr2 As Sheets
Set arr2 = Sheets(Array("Sheet1", "Sheet2", "Sheet3"))

I've been reading the message boards a lot lately, and have seen bopth
methods being used for creating arrays. I think one is set up as a
variable, but not sure. Anyway, they apparently differ in their use of
syntax, becasue I have tried meshing both styles into my code, and one

style
works while the other does not.

Just a general clarification would be greatly appreciated, or even better

a
link to a site that describes in detail the difference? Thanks a bunch!




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Array difference?

Steph,

Maybe the following will be of some help...

From "Using Arrays" in VBA help...
You can declare an array to work with a set of values of the same data type.
An array is a single variable with many compartments to store values,
while a typical variable has only one storage compartment in which it can store
only one value.
Refer to the array as a whole when you want to refer to all the values it holds,
or you can refer to its individual elements.

My note: you cannot use an "Array" without specifying how many items it contains.
So Dim arr1() is of no use until you ReDim it...
ReDim arr1(1 to 10)

From "Sheets Collection Object" in VBA help...
A collection of all the sheets in the specified or active workbook.
The Sheets collection can contain Chart or Worksheet objects.
Use Sheets(array) to specify more than one sheet.
The following example moves the sheets named "Sheet4" and "Sheet5"
to the beginning of the workbook.
Sheets(Array("Sheet4", "Sheet5")).Move befo=Sheets(1)

Regards,
Jim Cone
San Francisco, CA

"Steph" wrote in message ...
Hi. Was hoping someone could clarify something for me. What is the
difference between the following:
Dim arr1()
arr1 = Array("Sheet1", "Sheet2", "Sheet3")

Dim arr2 As Sheets
Set arr2 = Sheets(Array("Sheet1", "Sheet2", "Sheet3"))

I've been reading the message boards a lot lately, and have seen bopth
methods being used for creating arrays. I think one is set up as a
variable, but not sure. Anyway, they apparently differ in their use of
syntax, becasue I have tried meshing both styles into my code, and one style
works while the other does not.
Just a general clarification would be greatly appreciated, or even better a
link to a site that describes in detail the difference? Thanks a bunch!


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
Prevent cell/array references from changing when altering/moving thecell/array nme Excel Discussion (Misc queries) 1 September 19th 08 01:53 PM
Average of a difference between 2 cels in a table/array GCRDelphi Excel Worksheet Functions 0 July 18th 08 07:46 PM
Second largest in array of difference in high-low values in cells drb Excel Worksheet Functions 6 February 18th 08 02:29 AM
meaning of : IF(Switch; Average(array A, array B); array A) DXAT Excel Worksheet Functions 1 October 24th 06 06:11 PM
charting a difference of 2 columns' w/o adding a difference column Wab Charts and Charting in Excel 4 July 27th 05 02:37 AM


All times are GMT +1. The time now is 07:05 PM.

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

About Us

"It's about Microsoft Excel"