Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default array use problem

I am probably overlooking something really obvious. I have looked through
the online Excel & VB prog reference and it looks right to me. The following
code generates a "Compile Error - For Each may only iterate over a
collection object or an array.":

Dim MyFiles As String, I As Variant
MyFiles = Array("Consolidated.xls", "CAN1a.xls", _
"CAN1b.xls", "CAN1c.xls")
For Each I In MyFiles

Thanks for the help.

Nick


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default array use problem

You have to Dim MyFiles as Variant too.. not as String.

--
Regards

Juan Pablo González

"NikkoW" wrote in message
et.cable.rogers.com...
I am probably overlooking something really obvious. I have looked through
the online Excel & VB prog reference and it looks right to me. The

following
code generates a "Compile Error - For Each may only iterate over a
collection object or an array.":

Dim MyFiles As String, I As Variant
MyFiles = Array("Consolidated.xls", "CAN1a.xls", _
"CAN1b.xls", "CAN1c.xls")
For Each I In MyFiles

Thanks for the help.

Nick




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default array use problem

Doh!

See...I said it was obvious.

Thanks!


"Juan Pablo González" wrote in message
...
You have to Dim MyFiles as Variant too.. not as String.

--
Regards

Juan Pablo González

"NikkoW" wrote in message
et.cable.rogers.com...
I am probably overlooking something really obvious. I have looked

through
the online Excel & VB prog reference and it looks right to me. The

following
code generates a "Compile Error - For Each may only iterate over a
collection object or an array.":

Dim MyFiles As String, I As Variant
MyFiles = Array("Consolidated.xls", "CAN1a.xls", _
"CAN1b.xls", "CAN1c.xls")
For Each I In MyFiles

Thanks for the help.

Nick






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default array use problem

Sub tester2()
Dim MyFiles As Variant, I As Variant
MyFiles = Array("Consolidated.xls", "CAN1a.xls", _
"CAN1b.xls", "CAN1c.xls")
For Each I In MyFiles
Debug.Print I
Next
End Sub


Declare myfiles as Variant.

--
Regards,
Tom Ogilvy




"NikkoW" wrote in message
et.cable.rogers.com...
I am probably overlooking something really obvious. I have looked through
the online Excel & VB prog reference and it looks right to me. The

following
code generates a "Compile Error - For Each may only iterate over a
collection object or an array.":

Dim MyFiles As String, I As Variant
MyFiles = Array("Consolidated.xls", "CAN1a.xls", _
"CAN1b.xls", "CAN1c.xls")
For Each I In MyFiles

Thanks for the help.

Nick




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default array use problem

If the functions in the freely downloadable file at
http://home.pacbell.net/beban are available to your workbook, the
following will work:

Dim MyFiles() As String, I As Variant
Assign Array("Consolidated.xls", "CAN1a.xls", _
"CAN1b.xls", "CAN1c.xls"), MyFiles
For Each I In MyFiles

Alan Beban

NikkoW wrote:
Doh!

See...I said it was obvious.

Thanks!


"Juan Pablo González" wrote in message
...

You have to Dim MyFiles as Variant too.. not as String.

--
Regards

Juan Pablo González

"NikkoW" wrote in message
.net.cable.rogers.com...

I am probably overlooking something really obvious. I have looked


through

the online Excel & VB prog reference and it looks right to me. The


following

code generates a "Compile Error - For Each may only iterate over a
collection object or an array.":

Dim MyFiles As String, I As Variant
MyFiles = Array("Consolidated.xls", "CAN1a.xls", _
"CAN1b.xls", "CAN1c.xls")
For Each I In MyFiles

Thanks for the help.

Nick








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 733
Default array use problem

"Alan Beban" wrote...
If the functions in the freely downloadable file at
http://home.pacbell.net/beban are available to your workbook, the
following will work:

Dim MyFiles() As String, I As Variant
Assign Array("Consolidated.xls", "CAN1a.xls", _
"CAN1b.xls", "CAN1c.xls"), MyFiles
For Each I In MyFiles

.....

And what are the practical benefits to this compared to

Dim MyFiles As Variant
MyFiles = Array("Consolidated.xls", "CAN1a.xls", _
"CAN1b.xls", "CAN1c.xls")

That is, what are the advantages of declaring MyFiles as a dynamic array of
strings vs declaring it a variant that would hold a dynamic array of
strings? While the former uses 12 bytes less storage, calling another
procedure to assign the latter uses even more memory (since the procedure
would need to be in memory, and your code is likely to require more than 12
bytes), is slower and adds complexity? Is there anything to love about it?


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
3D Array Problem sgl Excel Worksheet Functions 2 July 6th 09 06:46 AM
Array problem, I think.. Steve Excel Worksheet Functions 3 June 11th 08 12:38 AM
Array problem - TIA S Davis Excel Worksheet Functions 9 November 7th 06 02:22 AM
Array Problem Phil Hageman[_3_] Excel Programming 0 November 19th 03 07:34 PM
Array Problem, Help Please. Bubu Excel Programming 9 November 18th 03 04:29 PM


All times are GMT +1. The time now is 01:20 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"