Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88868

Type mismatch error on importing values to an array

$
0
0

I m initializing an array and import values from a specific range. if the range are greater than one line the code works fine BUT in case the range is just one line i m getting an error of:

Run time error 13: Type mismatch

Code:

Sub test()

    Dim arr As Variant
    Dim i As Long, LastRow As Long

    With ThisWorkbook.Worksheets("Sheet1")

        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

        arr = .Range("A1:A"& LastRow)

        For i = LBound(arr) To UBound(arr)

        Next i

    End With

End Sub

Any help will appreciated.

After @JvdV answer i manage to overcome this problem but i face other one:

when there is more than one lines the array looks like that:

enter image description here

But when there is only one line:

enter image description here

How to create the same array structure - dimensions?


Viewing all articles
Browse latest Browse all 88868

Trending Articles