I have a custom Excel function that is supposed to take a range and count the number of values, where some cells may contain multiple /
-delimited values, each of which must be counted. Here's the function:
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
The trouble is, it's throwing #VALUE!
errors. In stepping through the function in the debugger, it seems like there's a problem with the line len_str = Len(split_str)
. I say this because whenever I get to this line in the debugger, it immediately stops debugging and does, essentially, an F5
. Obviously there's one or more bugs in my code, but without my debugger being willing to show me the errors, how can I debug it?
What's wrong with the code?