我一直在尝试设置传递给函数的范围的单元格的值,并且在设置单元格值时它总是抛出异常,即使我跟踪它以知道代码可以读取单元格值。下面的函数包含Case“XS”中始终创建异常的代码。请告诉我我做错了什么。
此函数在同一工作表中构建和设置输出表,其中累积了人工日数和%完成值。
输入:
IssueTable: 2D array of search data
Term1: 0 if searching for 0%, 1 if 100%, -1 if started (between 0 and 1)
Term1_Col: Column in IssueTabel containing %Done (leftmost is 1)
Filter: Filter term
Filter_Col: Column containing Filter
Size_Col: Column containing Filter
Effort_Col: Column containing level of Effort (LOE) data
Done_Col: Column containing %Done data
OutputTable: 2D array of output data
输出:
可输出: 范围填充表格中的数据:
Size LOE %Done
XS dd %%
S dd %%
M dd %%
L dd %%
XL dd %%
代码:
Public Function Build_SizeDistribution(IssueTable As Range, Term1 As
Integer, Term1_Col As Integer, Filter As String, Filter_Col As Integer,
Size_Col As Integer, Effort_Col As Integer, Done_Col As Integer,
OutputTable As Range)
Dim i As Integer
Dim state As String
Dim LOE As Variant
Dim retval As String
Dim dest As Range
Dim src As Range
Dim rng As Range
Dim ws As Worksheet
Set ws = ActiveSheet
ws.Activate
With ws
Set src = .Range(IssueTable.Address)
Set dest = .Range(OutputTable.Address)
For i = 1 To src.Rows.Count
If src.Cells(i, Term1_Col).Value = Term1 Or ((Term1 < 0) And (src.Cells(i, Term1_Col).Value > 0) And (src.Cells(i, Term1_Col).Value < 1)) Then
If src.Cells(i, Filter_Col).Value = Filter Then
state = src.Cells(i, Size_Col).Value
LOE = src.Cells(i, Effort_Col).Value
Select Case state
Case "XS"
Set rng = dest.Item(1, 2)
rng.Value = rng.Value + LOE
LOE = 3 ' just to have something for the debugger to stop on
Case "S"
Set rng = dest.Cells(2, 2)
rng.Value = rng.Value + LOE
Case "M"
Set rng = dest.Cells(3, 2)
rng.Value = rng.Value + LOE
Case "L"
Set rng = dest.Cells(4, 2)
rng.Value = rng.Value + LOE
Case "XL"
Set rng = dest.Cells(5, 2)
rng.Value = rng.Value + LOE
End Select
End If
End If
Next i
End With
Build_SizeDistribution = retval
End Function