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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
try deleting the red bit
Dim TransferArray() As Variant
 
Upvote 0

Forum statistics

Threads
1,215,343
Messages
6,124,398
Members
449,155
Latest member
ravioli44

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