excel - 如何在 VBA 中将以下 excel 函数重新创建为自定义函数:=IF(ISBLANK(I2), "late", IF(I2 > H2, "late", "on time"))
问题描述
这是我目前所拥有的,在尝试按如下方式调用函数后返回#NAME 错误:
=开启时间(H2,I2)
这是我的功能-第一次迭代和当前-在从相关线程尝试了一些事情之后:
=IF(ISBLANK(I2), “迟到”, IF(I2 > H2, “迟到”, “准时”))
第一次迭代
Function OnTime(RqstDate, ShipDate)
If IsEmpty(ShipDate) Then
OnTime = "late"
ElseIf ShipDate > RqstDate Then
OnTime = "late"
Else
OnTime = "On Time"
End Function
当前迭代
Function OnTime(RqstDate As Date, ShipDate As Date) As String
If IsEmpty(ShipDate) Then
OnTime = "late"
Exit Function
ElseIf ShipDate > RqstDate Then
OnTime = "late"
Exit Function
Else
OnTime = "On Time"
Exit Function
End Function
直接在 Excel 中键入的函数可以正常工作,但我的 VBA 尝试复制它时没有,我缺少什么才能使其正常运行?
解决方案
你在最后缺少一个End If:
Function OnTime(RqstDate As Date, ShipDate As Date) As String
If IsEmpty(ShipDate) Then
OnTime = "late"
Exit Function
ElseIf ShipDate > RqstDate Then
OnTime = "late"
Exit Function
Else
OnTime = "On Time"
Exit Function
End If 'THIS IS MISSING
End Function
编辑:你的功能在哪里?在您的 Excel 文件中创建一个模块并将您的函数存储在那里。在 ThisWorkbook 中创建的函数在工作表中将不可见。
(这已经过测试并且在工作表中工作正常)
推荐阅读
- c# - 如何确定 String.Split() 中使用的字符
- c# - cshtml中的多对多关系没有获取数据
- python - 元组的问题
- arrays - 引用单元格数据作为工作表名称源的一部分的 Google 工作表查询
- keep-alive - WireMock 保持活动状态
- objective-c - 如何使用 Objective-C 以编程方式将角半径添加到搜索栏?
- curl - curl --doh-url 是否不接受 dns 服务器的 IP 地址,并且响应只是 html?
- javascript - Angular - TypeError:无法读取未定义的属性“0”
- tensorflow - 自定义卷积层的梯度是无的
- list - 为什么我的绑定 [String] 不会更改我的多选列表 SwiftUI