2010-01-12 83 views
0

我有一個Excel表格,其中列有一個列表驗證。單元格值更改時彈出消息框

當從列表中選擇一個特定條目時,我需要彈出一個消息框。

我可以用下面的代碼,如果有隻有1個細胞,但對我來說,我有一列中許多細胞

Private Sub Worksheet_Change(ByVal Target As Excel.Range)  
    Dim rng As Range 
     Set rng = Range("A1") 
     If Not Intersect(Target, rng) Is Nothing Then 
      If rng = "hi" Then 
       MsgBox "Cell " & _ 
       rng.Address & " = hi" 
      End If 
     End If 
     Set rng = Nothing 
End Sub 

請幫

回答

1

檢查Target.Column的價值財產....

假設你要檢查列d(數值4),你做

Private Sub Worksheet_Change(ByVal Target As Range) 
    If Target.Column = 4 ' examine column D 
    ' code to validate Target 
     If Target = "xxx" Then MsgBox "You chose xxx from the list" 
    End If 
End Sub 

祝你好運MikeD