凭借多年的编程经验(不过是 VBA 初学者)、在线参考资料和搜索引擎,我仍然对无法使其正常工作感到非常沮丧。
我至少花了两个小时尝试 CInt、.Range、With/End With、.Value、Cells 等我可能想到的每一种组合,但它只是在“sum = sum + ... “ 线:
Public Sub Fill_InnerData()
Dim GNumber As Range
Set GNumber = Range("GenerateNumber")
Dim Data As Range
Set Data = Range("DATA_INNER")
For r = 1 To Data.Rows.Count
For c = 1 To Data.Columns.Count
If Data.Cells(r, c) = "" Then
If c > r Then
Data.Cells(r, c) = 0
Else
Dim x As Integer
x = r - c + 1
Dim y As Integer
y = 2
Dim sum As Integer
sum = 1
For i = 1 To c
sum = sum + CInt(Worksheets("Data").Range(Cells(x, y)).Value)
y = y + 1
Next
End If
End If
Next
Next
End Sub
“失败”是指收到此错误:
运行时错误“1004”:
应用程序定义或对象定义的错误
在我尝试过的每个组合中,我都在提到的行中收到了该错误。
我究竟做错了什么?