LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Named Array

I wish to programatically save data associated with particular Worksheet and
use in in other places in the Workbook.
With non-array data, this can be done using Name. E.G.,
Sub mySub()
Dim x As Variant
x = 345.678
y = 1234.5678
Worksheets("Sheet1").Names.Add Name:="SavedNumber", RefersTo:=x
Worksheets("Sheet2").Names.Add Name:="SavedNumber", RefersTo:=y
End Sub

Sub anotherSub()
Sheet1.Range("a1:a1").Value = [Sheet1.SavedNumber]
Sheet1.Range("a2:a2").Value = [Sheet2.SavedNumber]
End Sub

This works just fine. Note that I use the same name, SavedNumber, overloaded
for each Worksheetsheet, making it
easy to write general functions.

Now, back to the array. If I try to use arrays LOCAL to specific Worksheets,
it fails. If I make a global array, it works.
That is, this fails:
Sub ArrayToName()
Dim MyArray(1 To 3)
MyArray(1) = 1.1
MyArray(2) = 2.2
MyArray(3) = 3.3
Worksheets("Sheet1").Names.Add Name:="SavedArray", RefersTo:=MyArray
End Sub

Sub UseArray()
Dim i As Integer
Dim tmpStr As String
Dim x As Double
Dim MyArray As Variant

MyArray = [Sheet1.SavedArray]

For i = 1 To 3
tmpStr = "a" & CStr(i + 8)
x = MyArray(i)
Sheet2.Range(tmpStr).Value = x
Next i

End Sub

However, if I remove the Worksheets("Sheet1") and the Sheet1. it works.

So, is this a VBA quirk, IOW, and undocumented "feature"?

TIA

Ed


 
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
Referencing a named array mooresk257 Excel Discussion (Misc queries) 1 October 26th 09 08:14 PM
Using Named Range within an Array Formula Ivor Davies Excel Discussion (Misc queries) 2 August 25th 09 11:15 AM
Named Array KC Excel Qns Excel Worksheet Functions 7 July 22nd 09 05:33 AM
Named Ranges in Array Formulas jfitzpat Excel Worksheet Functions 2 May 20th 08 11:34 PM
Named range into an array Frigster Excel Worksheet Functions 2 September 6th 06 07:08 PM


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