View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
gocush[_29_] gocush[_29_] is offline
external usenet poster
 
Posts: 252
Default How to use workbook_open()?

In your code you are declaring the variable, including your array with Dim
statements. This means that they are only "valid" for the duration of the
sub or procedure. With "End Sub" these variable cease to exist.

When you say that you then try to show the myarray, it fails because it no
longer exists. You must do something with your array while still inside the
macro.

Alternatively, you can declare variables with a Public statement at the very
top of a module, RATHER than within the macro. This will cause the variable
to retain values beyond a single macro.

As for using variable in more than one Sheet -- there is no connection
between variables and sheets. In a macro you can declare a variable, give
it a value, then use it with any sheet:
ActiveSheet.Range("C5")=MyVar
Sheets("Customers").Range("CurrCust")=MyVar

HTH

"Susan Hayes" wrote:

Hello

Im trying to read a range of entries, but Im not sure how this works.

Under the excel objects in "this workbook" I wrote:

Public Sub Workbook_Open()

Dim i As Single
Dim j As Single
Dim myarray(18, 10)

For i = 1 To 18
For j = 1 To 10
myarray(i, j) = Worksheets("schedule").Cells(i + 3, Chr(68 + j))
Next
Next
End Sub



After in sheet1 I try to display the myarray to see if it was read but doesnt work. Can anyone help me with this?
Im also not sure how to pass variables between sheets, I can only do it within the same sheet.
Any help is greatly appreciate. This newsgroup has helped me alot
Thank you

Mike