我已经编写了下面的程序,每次我尝试运行它时编译说Data
是错误的数据类型。 ChooseLineItem
将范围作为参数,如您所见Data
不是范围,则ChooseLineItem
将不会被执行。
所以我的问题是如何编译这段代码?
Public Function MakeKeyValPairs(Data As Variant) As Variant()
Dim LineItem As Integer
Dim Headers As KeyValStruct
If TypeName(Data) = "Range" Then
LineItem = ChooseLineItem(Data)
Else
LineItem = 1
End If
Headers = FindHeaders(Data)
MakeKeyValPairs = AssembleAray(Data, Headers, LineItem)
End Function
仅供参考Data
被视为变体的原因是因为它必须能够接受范围和数组。
答案 0 :(得分:3)
试试这个:
Public Function MakeKeyValPairs(Data As Variant) As Variant()
Dim LineItem As Integer, Headers As KeyValStruct, r as Range
If TypeName(Data) = "Range" Then
Set r = Data
LineItem = ChooseLineItem(r)
Else
LineItem = 1
End If
Headers = FindHeaders(Data)
MakeKeyValPairs = AssembleAray(Data, Headers, LineItem)
End Function