我有一些 VBA 代码可以根据前一个单元格的值更新许多单元格的值。目前,我可以让它为一行信息工作。但是,我希望它可以用于不止一排。我一直在编写和复制+粘贴代码,所以很有可能只是缺乏连贯性。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rwIndex As Integer
For rwIndex = 4 To 400
If Target.Address = Cells(rwIndex, 3) Then
If Range(Target.Address).Value = "Intrinsic" Then
Dim LYVMessage
LYVMessage = "Enter Last Year's Value"
Cells(rwIndex, 5).Value = InputBox(LYVMessage)
Else
Cells(rwIndex, 5).Value = "NA"
Cells(rwIndex, 6).Value = "NA"
Cells(rwIndex, 9).Value = "NA"
Cells(rwIndex, 10).Value = "NA"
Cells(rwIndex, 11).Value = "NA"
Cells(rwIndex, 12).Value = "NA"
Cells(rwIndex, 7).Value = "NA"
Cells(rwIndex, 8).Value = "NA"
QMessage = "Enter whether Quantity is a Fixed Variable (1) or Random Variable (Logistic or Triangular)"
Cells(rwIndex, 13).Value = InputBox(QMessage)
PMessage = "Either Enter a Fixed Value for Price, or Enter Whether it is a Random Variable (Logistic or Triangular)"
Cells(rwIndex, 14).Value = InputBox(PMessage)
End If
End If
Next rwIndex
End Sub
当我更新目标单元格时,我收到一条错误消息:“编译错误:未定义子或函数。”
谁能告诉我发生了什么事?