2016-10-27 6 views
1

現在、ユーザーが自分の数式の1つをシートに上書きすると、vbaモジュールを呼び出そうとしています。私は、ワークシート変更イベントがトリガしていると思うが、モジュールを実行するときにランタイムエラー424( "オブジェクトが必要")が表示される。私は何が間違っているのか分からないのですか?コードをトリガーしようとすると実行時エラー424オブジェクトが必要になる

Sub Award_Amount_Entered() 

    'If the user has overwritten the formula that was just in the cell 

If ActiveCell.HasFormula = False Then 
Applicaton.Intersect((Rows(ActiveCell.Row)), Range("AA:AA")).Select 

....run some more code 

End If 

End Sub 

デバッグは、VBAは、上記のコードの最後の行をハイライトする:アプリケーションここで私が呼んでいるモジュール内のコードがあります

Private Sub Worksheet_Change(ByVal Target As Range) 

If Not Intersect(Target, Range("Award_Amount")) Is Nothing Then 
Call Award_Amount_Entered 
End If 

If Not Intersect(Target, Range("Award_two_Amount")) Is Nothing Then 
Call Award_two_Amount_Entered 
End If 
End Sub 

は、ここに私のワークシート変更イベントのコードです.Intersect((行(ActiveCell.Row))、範囲( "AA:AA"))を選択してください。

これは以前使用されていたと確信しています!私は何か間違っているのですか?

この記事を読む時間を割いてくれてありがとうございます!コード内のコメント

ティナ

+0

が完全に行プロパティを修飾してください。 – Brian

+2

また、間違ったアプリケーションのスペルもあります。 – Brian

+1

シートコードモジュールでは、すべてのRange()およびCells()呼び出しがシートオブジェクトにデフォルト設定されますが、これは通常のモジュールのコードでは当てはまりませんので、より具体的にすることをお勧めします。 –

答えて

0

いくつかの提案:

Private Sub Worksheet_Change(ByVal Target As Range) 
    Dim rng As Range 

    Set rng = Intersect(Target, Me.Range("Award_Amount")) 

    If Not rng Is Nothing Then 
     Award_Amount_Entered rng  '<<< pass rng to the called procedure 
    End If 

    Set rng = Intersect(Target, Me.Range("Award_two_Amount")) 

    If Not rng Is Nothing Then 
     Award_two_Amount_Entered rng '<<< pass rng to the called procedure 
    End If 


End Sub 

呼び出され、サブ:

Sub Award_Amount_Entered(rng As Range) 

    Dim c As Range, c2 As Range 

    'Remember, Target can be a multi-cell range, so loop over 
    ' all of the cells in the "rng" parameter... 

    On Error GoTo haveError 'handle any errors 

    For Each c In rng.Cells 
     'If the user has overwritten the formula that was just in the cell 
     If Not c.HasFormula Then 

      'Use a range variable instead of selecting the cell 
      ' and then operating on the selection 
      Set c2 = c.EntireRow.Cells(1, "AA") 

      'If you're going to update the sheet here then it's good practice 
      ' to disable events 
      Application.EnableEvents = False 
      'update sheet 
      Application.EnableEvents = True 

     End If 
    End If 
    Exit Sub 

haveError: 
    'If your code errors you need to make sure you re-enable events 
    ' (at the very least) before exiting 
    Application.EnableEvents = True 

End Sub 
関連する問題