excel - 查找 VBA 数组的长度
问题描述
我有一个自定义 Excel 函数,它应该采用一个范围并计算值的数量,其中一些单元格可能包含多个/
- 分隔的值,每个值都必须计算在内。这是功能:
Option Explicit
Public Function COUNT_RACKS(rack_range As Range) As Integer
Dim total As Integer
Dim cell As Range
Dim split_str As Variant
Dim len_str As Integer
total = 0
For Each cell In rack_range.Cells
If Len(cell.Value) > 0 Then
If InStr(cell.Value, "/") <> 0 Then
split_str = Split(cell.Value, "/")
len_str = Len(split_str)
total = total + len_str
Else
total = total + 1
End If
End If
Next cell
COUNT_RACKS = total
End Function
问题是,它会抛出#VALUE!
错误。在调试器中单步执行该函数时,该行似乎存在问题len_str = Len(split_str)
。我这样说是因为每当我在调试器中到达这一行时,它会立即停止调试,并且本质上是一个F5
. 显然我的代码中有一个或多个错误,但是如果我的调试器不愿意向我显示错误,我该如何调试它?
代码有什么问题?
解决方案
推荐阅读
- php - 用于下载存储在 MySQL 数据库中的 JSON 的 HTML 函数
- vue.js - VS Code - 在 .vue 文件中启用 autoClosingTags 选项
- symfony - 将字段插入联合表原则
- selenium-webdriver - 如何让摩卡测试等到执行完成
- mysql - 如何从已知外键列的表中进行选择
- assembly - 如何计算x86中2的幂序列的总和?
- javascript - 如何在带有链接的数组中进行匹配并获取数组的 id 和值?
- ios - 倒数计时器如何在后台工作
- ruby-on-rails - puma 中的 HTTPS 重定向仅适用于基本 URL
- vue.js - 类绑定中需要反引号(`)?