调用UDF时,公式中使用的值是错误的数据types
我一直在努力弄清楚这里出了什么问题。 我有两个包含string值的列。 我使用第三个col来调用工作表中的UDF,但最终得到#Value错误 – “公式中使用的值是错误的数据types”。
例如:
Col I Col J File1 Y File1 N File2 Y File3 N
我试着debugging它,并将input值正确地传递给函数variables。 我在VBA的知识是有限的,希望你们能帮我解决这个问题。
在工作表中调用的函数:
=FileCheck(I3,I3:J38)
码:
Public Function FileCheck(V As Range, Q As Range) As String Dim vtest As Variant Dim i, j, stat As Integer stat = 0 vtest = Q For i = 1 To UBound(vtest) If V = vtest(i, 1) And vtest(i, 2) = "N" Then For j = 1 To UBound(vtest) If V = vtest(j, 1) And vtest(j, 2) = "Y" Then FileCheck = "Y" stat = 1 End If Next If stat = 0 Then FileCheck = "N" End Else: End End If ElseIf V = vtest(i, 1) And vtest(i, 2) = "Y" Then FileCheck = "Y" End If Next End Function
您正在使用End
,因此出现此错误。
当你想closures你的电脑时,你是否点击Start Menu ~~> Shut down
或者直接拉出电源线? 🙂
使用End
与拉电缆非常相似。 不要使用End
。 优雅地退出该function。 End
语句基本上是使程序崩溃的一种方式,但不显示任何错误消息。
尝试这个。 replace这些行
If stat = 0 Then FileCheck = "N" End Else: End End If
同
If stat = 0 Then FileCheck = "N" Exit Function
编辑
顺便说一句,你是否试图在Col J
findCol I
的相应值? 如果是的话,那么你不需要这个UDF。 你可以使用Vlookup()
使用此公式=VLOOKUP(I3,I3:J38,2,0)
而不是=FileCheck(I3,I3:J38)
我认为你的第一个inputtypes应该是一个string而不是范围:
V as string
另外你需要使用exit function
当你想结束函数,但我不知道如果你想结束函数,结束if语句或for循环?