parry
MrExcel MVP
- Joined
- Aug 20, 2002
- Messages
- 3,355
I have data in column A from row 1 downwards. All the data in Column A is a string being FileName1, FileName2 etc. However, even though the data in column A is a string when I try to put this directly into an array it comes up with a RunTime Error 13 - Type Mismatch.
If I change the array data type to a variant then it works. Why? I know you can have arrays of any type so why is this failing when the source data is of the same type as the array. Any clues would be appreciated.
This doesnt work
This works
If I change the array data type to a variant then it works. Why? I know you can have arrays of any type so why is this failing when the source data is of the same type as the array. Any clues would be appreciated.
This doesnt work
Code:
Sub Test1()
'THIS FAILS WITH RUN TIME ERROR 13: TYPE MISMATCH
Dim SourceArr() As String
'Place data source into an array
If IsEmpty([a65536]) Then
SourceArr = Range("a1:a" & Range("a65536").End(xlUp).Row)
Else
SourceArr = [a1:a65536]
End If
End Sub
This works
Code:
Sub Test2()
'THIS WORKS
Dim SourceArr() As Variant
'Place data source into an array
If IsEmpty([a65536]) Then
SourceArr = Range("a1:a" & Range("a65536").End(xlUp).Row)
Else
SourceArr = [a1:a65536]
End If
End Sub