Filter type mismatch

vbastruggle

New Member
Joined
Mar 12, 2018
Messages
6
Hello everyone.

I am trying to filter an array within a sub procedure and get a type mismatch error that I can't figure out.

dim array1
dim find as string

find= "1"
array1= Split("1,2,3,4,5", ",") This creates a one dimension array with a data type variant/string
found = filter(array1,"1") This throws a type mismatch error

Any help would be greatly appreciated. Thanks!
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
You don't use string "find", so it's useless in your code.

Code:
    Dim Array1, found As Variant
    
    Array1 = Split("1,2,3,4,5,6", ",")
    found = Filter(Array1, "1")
    
    For Each arr In found
        Debug.Print arr
    Next arr

This worked for me

Can you send the "Split" and "Filter" you are actually doing ?
 
Last edited:
Upvote 0
You don't use string "find", so it's useless in your code.

Code:
    Dim Array1, found As Variant
    
    Array1 = Split("1,2,3,4,5,6", ",")
    found = Filter(Array1, "1")
    
    For Each arr In found
        Debug.Print arr
    Next arr

This worked for me

Can you send the "Split" and "Filter" you are actually doing ?

I just got it working. Your for each statement got me to realize that the filter returns an array. I knew that in my test I should have only matched on one row so I was expecting a single value and wasn't thinking it would be an array with a single value. Anyhow, it is working now. Thanks!
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,701
Members
448,980
Latest member
CarlosWin

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