2017-07-30 18 views
1
Private Sub Worksheet_Change(ByVal Target As Range) 
    Dim KeyCells As Range 

    ' The variable KeyCells contains the cells that will 
    ' cause an alert when they are changed. 
    Set KeyCells = Range("z12:z15") 

    If Not Application.Intersect(KeyCells, Range(Target.Address)) Is Nothing Then 
     If Range("Z12:Z45).value = "yes" then 
      MsgBox "Cell " & Target.Address & " has changed." 
     End If 
    End If 
End Sub 

この問題を解決するには問題があります。どんな助けもありがとう。 VBAで TXVBAが優秀なセル範囲のマクロを実行します。

ルイージ

+0

「ターゲット」(変更された)範囲のセルに「はい」があるかどうかを確認する必要がありますか? –

+0

そうです。このコードは今私にエラーを与えている。 –

+0

_Target_は範囲です...使用する '... Application.Intersect(KeyCells、Target)...' – jsotola

答えて

4

、あなたは定数(「はい」)、またはそのことについて何かを配列(Range("Z12:Z45").value)を比較することはできません。範囲のセル(または配列のエントリ)をループするか、おそらくMatchまたはCountIf関数を使用する必要があります。

さらに、変更を確認するには、Targetの範囲を調べる必要があります。Range("z12:z15")ではありません。

Private Sub Worksheet_Change(ByVal Target As Range) 
    Dim KeyCells As Range, cel As Range 

    ' The variable KeyCells contains the cells that will cause an alert when they are changed. 
    Set KeyCells = Range("z12:z15") 

    If Not Intersect(KeyCells, Target) Is Nothing Then 
     For Each cel In Intersect(KeyCells, Target) 
     If StrComp(cel.text, "yes", vbTextCompare) = 0 Then 
      MsgBox "Cell " & cel.Address & " has changed." 
     End If 
     Next 
    End If 
End Sub 
+1

は、 !あなたの知識を共有していただきありがとうございます。 –

関連する問題