Private Sub FillRow(programCell As Range, storedProgramCell As Range)
Dim counter As Integer
For counter = 3 To 9
Dim cellOffset As Integer
cellOffset = counter - 3
Dim currentStoredCell As Range
Set currentStoredCell = storedProgramCell.Offset(0, cellOffset)
Dim value As String
value = currentStoredCell.value
Dim currentTargetCell As Range
Set currentTargetCell = programCell.Offset(0, cellOffset)
MsgBox currentStoredCell.value 'Works correctly, prints correct value
currentTargetCell.value = value
Next counter
End Sub
该行:
currentTargetCell.value = value
导致代码停止执行,没有错误。
我将表达式添加到我的监视列表中,然后逐步完成例程。该表达式被视为Boolean
:
这使我认为表达式被视为比较,并且程序突然结束,因为返回的Boolean
未被存储或在任何地方使用。我不怀疑我是不是错了。
我是VBA的新手,正在努力调试我的程序,所以请原谅我,如果这是一个小错误。我在网上找不到任何解释这个问题的资料。
答案 0 :(得分:1)
用以下代码替换您的子程序:
Private Sub FillRow(Dst As Range, Src As Range)
Dim x As Integer
Dim v As Variant
Dim Srcx As Range
Dim Dstx As Range
Debug.Print "FillRow"
Debug.Print Src.Address
Debug.Print Dst.Address
Debug.Print "Loop"
For x = 0 To 6
Debug.Print x
Set Srcx = Src.Offset(0, x)
Debug.Print Srcx.Address
v = Srcx.Value
Debug.Print TypeName(v)
Set Dstx = Dst.Offset(0, x)
Debug.Print Dstx.Address
Dstx.Value = v
Next
Debug.Print "Completed"
End Sub
在您的问题中运行并发布立即窗口输出。
答案 1 :(得分:0)
值是一个保留字,即使vba没有引起此名称的错误,也不应该使用它。把它命名为别的。另外,尝试将其设置为变体。