M
MichaelDavid
Greetings! This one has me totally baffled.
In Sub ArrayStudies1, MyArray is dimensioned as an array of type Integer.
MyArray is then ReDim'ed, Ranges A1 through A3 are set to integers,
successive array locations are set to these ranges, and the first array
location is successfully displayed.
Sub ArrayStudies2 differs from Sub ArrayStudies1 only in that the array
MyArray is set to a 3 cell range having integers. In this case, upon
execution, I get the message " "Run-time error '13': Type mismatch".
Sub ArrayStudies3 differs from Sub ArrayStudies2 only in that MyArray is
declared as a dynamic array of type Variant rather than as type Integer. And
this worked perfectly with no error messages. Why can't MyArray be declared
as an array of type Integer in Sub ArrayStudies2? (At the top of the module
containing these three subs is: Option Base 1)
Sub ArrayStudies1()
' example patterned after Excel VBA Help on ReDim statement:
' This example uses the ReDim statement to allocate and reallocate storage
space for dynamic-array variables. It assumes the Option Base is 1.
Dim MyArray() As Integer ' Declare dynamic array of type Integer.
ReDim MyArray(3) ' Allocate 3 elements.
Range("A1") = 1
Range("A2") = 2
Range("A3") = 3
MyArray(1) = Range("A1")
MyArray(2) = Range("A2")
MyArray(3) = Range("A3")
' The following instruction works fine:
MsgBox "MyArray(1) = " & MyArray(1)
End Sub
-------------------------------------------------------------------------------------------------
Sub ArrayStudies2()
Dim MyArray() As Integer ' Declare dynamic array of type Integer.
ReDim MyArray(3) ' Allocate 3 elements.
Range("A1") = 1
Range("A2") = 2
Range("A3") = 3
' The follwg instr gives: "Run-time error '13': Type mismatch"
MyArray = Range("A1:A3") ' Initialize array.
MsgBox "MyArray(1, 1) = " & MyArray(1, 1)
End Sub
-------------------------------------------------------------------------------------------------
Sub ArrayStudies3()
Dim MyArray() ' Declare dynamic array of type Variant.
ReDim MyArray(3) ' Allocate 3 elements.
Range("A1") = 1
Range("A2") = 2
Range("A3") = 3
' The follwg instr works fine
MyArray = Range("A1:A3") ' Initialize array.
MsgBox "MyArray(1, 1) = " & MyArray(1, 1)
End Sub
May you have a most blessed day!
Sincerely,
Michael Fitzpatrick
In Sub ArrayStudies1, MyArray is dimensioned as an array of type Integer.
MyArray is then ReDim'ed, Ranges A1 through A3 are set to integers,
successive array locations are set to these ranges, and the first array
location is successfully displayed.
Sub ArrayStudies2 differs from Sub ArrayStudies1 only in that the array
MyArray is set to a 3 cell range having integers. In this case, upon
execution, I get the message " "Run-time error '13': Type mismatch".
Sub ArrayStudies3 differs from Sub ArrayStudies2 only in that MyArray is
declared as a dynamic array of type Variant rather than as type Integer. And
this worked perfectly with no error messages. Why can't MyArray be declared
as an array of type Integer in Sub ArrayStudies2? (At the top of the module
containing these three subs is: Option Base 1)
Sub ArrayStudies1()
' example patterned after Excel VBA Help on ReDim statement:
' This example uses the ReDim statement to allocate and reallocate storage
space for dynamic-array variables. It assumes the Option Base is 1.
Dim MyArray() As Integer ' Declare dynamic array of type Integer.
ReDim MyArray(3) ' Allocate 3 elements.
Range("A1") = 1
Range("A2") = 2
Range("A3") = 3
MyArray(1) = Range("A1")
MyArray(2) = Range("A2")
MyArray(3) = Range("A3")
' The following instruction works fine:
MsgBox "MyArray(1) = " & MyArray(1)
End Sub
-------------------------------------------------------------------------------------------------
Sub ArrayStudies2()
Dim MyArray() As Integer ' Declare dynamic array of type Integer.
ReDim MyArray(3) ' Allocate 3 elements.
Range("A1") = 1
Range("A2") = 2
Range("A3") = 3
' The follwg instr gives: "Run-time error '13': Type mismatch"
MyArray = Range("A1:A3") ' Initialize array.
MsgBox "MyArray(1, 1) = " & MyArray(1, 1)
End Sub
-------------------------------------------------------------------------------------------------
Sub ArrayStudies3()
Dim MyArray() ' Declare dynamic array of type Variant.
ReDim MyArray(3) ' Allocate 3 elements.
Range("A1") = 1
Range("A2") = 2
Range("A3") = 3
' The follwg instr works fine
MyArray = Range("A1:A3") ' Initialize array.
MsgBox "MyArray(1, 1) = " & MyArray(1, 1)
End Sub
May you have a most blessed day!
Sincerely,
Michael Fitzpatrick