将两个值传递给子例程

时间:2017-01-20 19:56:23

标签: excel vba

我试图将target.value和target.address传递给我的子例程,但由于某种原因我得到错误"预期:="。

Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.Address = "$A$2" Then
      sendToRoutine (Target.Address, Target.Value) <<== Error
   End If
End Sub


Sub sendToRoutine ( myTarget as String, myTargetValue as String)
   'Do Something with the values....
End Sub

1 个答案:

答案 0 :(得分:1)

您在功能面前缺少Call

Sub Worksheet_Change(ByVal Target As Range)
   If Target.Address = "$A$2" Then
      Call sendToRoutine(Target.Address, Target.Value) '<<== Not an error
   End If
End Sub


Sub sendToRoutine(myTarget As String, myTargetValue As String)
   'Do Something with the values....
End Sub