run-time error 13: type mismatch, though type is the same

littlerascal

New Member
Joined
Oct 10, 2015
Messages
3
Hello everyone

Below you see a part of a subroutine where I want to assign an array, which I create with a function (displayed further down) to an element of an array. To my understanding this should result in a jagged array. Unfortunately i get a run-time error 13: type mismatch on the line of the assignment.

Code:
For Each cell In Sourcerange
        If cell.Value <> "" Then
            ReDim Preserve TransferArray(count)
            TransferArray(count) = InitValues(Target(1), TargetCell(1))
            count = count + 1
        End If
Next cell

Here you see the type assignment that was made at the beginning of the sub.


Code:
Dim TransferArray() As Variant


And these are the relevant parts of the function, which creates the array I want to assign to the array in the sub.


Code:
Function InitValues(Sourcerange As range, Target As Sheets, TargetCell As range) As Variant()

...


Set TargetRange = range(TargetCell, range(TargetCell.Offset(0, 82)))
        For Each cell In TargetRange
            If cell.Interior.ColorIndex <> 19 Or 1 Then
                InitArray(count) = cell.Value
                count = count + 1
            End If
        Next
End function

As you see both arrays are variant, so the types are the same. I just started to use VBA recently, so don't blame me, if I made a stupid mistake :P

Thanks a lot in advance for any reply.

Kind regards
littlerascal
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
try deleting the red bit
Dim TransferArray() As Variant
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top