itchyII
MIS
- Apr 10, 2001
- 167
Hi all,
I am trying to populate an array with a named range in Excel and then search the array for a value. All I have read on it has suggested that I should be able to use the 'Filter' funtion to accomplish this, but I keep getting a Type Mismatch error. As I understand it, the search criteria in the function must be a string, but my array is a variant (this is what works best for popuating with a range of cells). But I am seeing many examples out there that search a string into a variant array, so why am I getting the error? I have been trying to get this for too long! I figure it should be pretty simple. What am I missing?
Dim a As Integer
Dim y As Integer
Dim key As String
Dim keyArray() As Variant
Dim found As Variant
'count rows
x = countRows(Range("A1"))
'set named range
Range("B2:B" & x).Select
ActiveWorkbook.Names.Add Name:="_key", RefersToR1C1:= _
"=GroupConversionReport!R2C2:R" & x & "C2"
ActiveWorkbook.Names("_key").Comment = ""
'populate array
keyArray() = Range("_key")
'select other sheet
Sheets("ProjectViewGroups_B").Select
'count rows
y = countRows(Range("A1"))
a = 2
Range("N1").Select
ActiveCell.FormulaR1C1 = "Rule Found"
While a <> y
Range("N" & a).Select
If ActiveCell.Offset(0, -11).Value = "Project" Then
key = ActiveCell.Offset(0, -10).Value & ActiveCell.Offset(0, -7) & ActiveCell.Offset(0, -4)
found = Filter(keyArray, key)
a = y
Else
a = a + 1
End If
Wend
I am trying to populate an array with a named range in Excel and then search the array for a value. All I have read on it has suggested that I should be able to use the 'Filter' funtion to accomplish this, but I keep getting a Type Mismatch error. As I understand it, the search criteria in the function must be a string, but my array is a variant (this is what works best for popuating with a range of cells). But I am seeing many examples out there that search a string into a variant array, so why am I getting the error? I have been trying to get this for too long! I figure it should be pretty simple. What am I missing?
Dim a As Integer
Dim y As Integer
Dim key As String
Dim keyArray() As Variant
Dim found As Variant
'count rows
x = countRows(Range("A1"))
'set named range
Range("B2:B" & x).Select
ActiveWorkbook.Names.Add Name:="_key", RefersToR1C1:= _
"=GroupConversionReport!R2C2:R" & x & "C2"
ActiveWorkbook.Names("_key").Comment = ""
'populate array
keyArray() = Range("_key")
'select other sheet
Sheets("ProjectViewGroups_B").Select
'count rows
y = countRows(Range("A1"))
a = 2
Range("N1").Select
ActiveCell.FormulaR1C1 = "Rule Found"
While a <> y
Range("N" & a).Select
If ActiveCell.Offset(0, -11).Value = "Project" Then
key = ActiveCell.Offset(0, -10).Value & ActiveCell.Offset(0, -7) & ActiveCell.Offset(0, -4)
found = Filter(keyArray, key)
a = y
Else
a = a + 1
End If
Wend