我在VBA中有以下子功能:
Sub test()
index_match_array(Range("D5").Value,Range("BZ:BZ").DataSeries,"Hardware",1,2)
End Sub
这会调用以下开始的函数:
Option Explicit
Function index_match_array(loookup As String, table_array As Range, criteria_search As String, criteria_line_add As Integer, return_line_add As Integer) As String()
Dim lookup_array() As String
Dim result_array() As String
...
...
index_match_array = result_array
End Function
当我编译时,我收到错误消息:
编译错误: 语法错误
我怀疑它是关于第二个参数,范围一,但我不确定?
答案 0 :(得分:1)
' Data Series返回类型为Variant,将table_array更改为Variant '函数在Array中,将函数index_match_array更改为String
Option Explicit
Sub test()
Dim sString(10) As String
sString(1) = index_match_array(Range("D5").Value, Range("BZ:BZ").DataSeries, "Hardware", 1, 2)
End Sub
Function index_match_array(loookup As String, table_array As Variant, criteria_search As String, criteria_line_add As Integer, return_line_add As Integer) As String
Dim lookup_array(10) As String
Dim result_array(10) As String
result_array(1) = "Test Value"
index_match_array = result_array(1)
End Function