【发布时间】:2013-02-02 02:24:35
【问题描述】:
VBE 调试器不断给我
1004 error (Application-defined or object-defined error)
在线"Worksheets("General").Cells(cur_index, 2).Value = cur_time"
或我尝试真正修改单元格值的任何尝试。
从同一工作表中的单元格调用该函数。但是当我输入的时候?
在即时窗口中的活动表,没有任何显示。怎么了?
谁能告诉我如何解决它以及问题出在哪里?谢谢。
更新:这是我的代码的一部分,我的代码开头确实有明确的选项。
Function collectdata(cur_time)
Dim row_num As Integer, start_index As Integer, end_index As Integer, cur_index As Integer, col_num As Integer
row_num = 1
start_index = total_record * num_it + 21
end_index = start_index + total_record - 1
Dim rg As String
rg = "A" & start_index & ":A" & end_index
On Error GoTo err1
If cur_time > 0 And num_it < 10 Then
cur_index = cur_time + 1200 * num_it
Worksheets("General").Cells(cur_index, 2).Value = cur_time
Worksheets("General").Range(rg).Value = num_it + 1
For col_num = 3 To 12
Worksheets("General").Cells(cur_index, col_num).Value = Cells(7, col_num).Value
Next col_num
ElseIf cur_time = 1200 Then
num_it = num_it + 1
End If
err1:
Debug.Print Err.Description
End Function
【问题讨论】:
-
用作 UDF 的 VBA 函数无法修改工作簿 - 它只能返回一个值或值数组。
-
正如@TimWilliams 提到的,您不能修改UDF 中除自身之外的其他单元格。你可以在 VBA 中运行函数吗?如果是---> 那就是问题,如果不是--> 最好指定 cur_time 的类型。