|
-
Apr 29th, 2013, 05:13 PM
#1
Thread Starter
New Member
Excel Table Range into Array and IsInArray function
Hello,
I am a first time poster but a longtime admirer of the work and help provided on this forum.
I have been banging my head on this and finally decided that I need to get some help. I am getting a type-mismatch error and I am not using Option Explicit. r = 19 so there are not many rows.
Code:
Sub TestArray()
Dim r As Integer
r = Range("ObjCode[[#All],[Cleaning]]").Rows.Count
ReDim aFUNC(1 To r, 1 To 1) As Variant
aFUNC = Range("ObjCode[[#All],[Cleaning]]")
Debug.Print aFUNC(11, 1)
If IsInArray(Range("G8").Value, aFUNC) Then
MsgBox "Yeah!"
End If
End Sub
Function IsInArray(stringToBeFound As Variant, arr As Variant) As Boolean
IsInArray = (UBound(Filter(arr, stringToBeFound)) > -1)
End Function
Any help is greatly appreciated
Kles
-
Apr 30th, 2013, 01:33 PM
#2
Re: Excel Table Range into Array and IsInArray function
Kles
Welcome to the Forums 
What line of your code is throwing the error?
Spoo
-
Apr 30th, 2013, 03:52 PM
#3
Thread Starter
New Member
Re: Excel Table Range into Array and IsInArray function
The error occurs on:
IsInArray = (UBound(Filter(arr, stringToBeFound)) > -1)
I think it is because arr is a one-dimensional array. I am not sure how to use the filter function on a 2-dimensional array. Thanks
-
May 1st, 2013, 07:15 AM
#4
Re: Excel Table Range into Array and IsInArray function
from help
Remarks
If no matches of match are found within sourcearray, Filter returns an empty array. An error occurs if sourcearray is Null or is not a one-dimensional array.
The array returned by the Filter function contains only enough elements to contain the number of matched items.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|