2014-11-05 31 views
0

我有一個工作表,其中包含列D中的發票號。我想在選擇一個工作表時將發票號複製到另一個工作表(「詳細信息」)。我添加了「If IsNumeric」條件,以確保只有包含發票#的單元格纔會被複制。代碼似乎什麼都不做,任何人都可以幫助我指出正確的方向嗎?對於特定列的工作表_選擇更改

Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Column = 4 Then On Error Resume Next Application.EnableEvents = False If IsNumeric(Target.Value) Then Sheets("Detail").Range("A5").Value = Target.Value Application.EnableEvents = True Sheets("Detail").Activate End If End If End Sub

回答

0

不是:

IsNumeric(Target.Address) 

嘗試

IsNumeric(Target) 

編輯#1:

試試這個:

Private Sub Worksheet_SelectionChange(ByVal Target As Range) 
    If Target.Column = 4 Then 
     Application.EnableEvents = False 
     If IsNumeric(Target.Value) Then 
      Target.Copy Sheets("Detail").Range("A5") 
     End If 
     Application.EnableEvents = True 
    End If 
End Sub 

編輯#2:

你需要在同一個IF

Private Sub Worksheet_SelectionChange(ByVal Target As Range) 
    If Target.Column = 4 Then 
     On Error Resume Next 
      If IsNumeric(Target.Value) Then 
       Application.EnableEvents = False 
       Sheets("Detail").Range("A5").Value = Target.Value 
       Sheets("Detail").Activate 
       Application.EnableEvents = True 
      End If 
    End If 
End Sub 
+0

我想這個問題,以及則IsNumeric(目標重新啓用事件。價值),並且當我點擊任何單元格時,仍然沒有任何反應 – Jason 2014-11-05 18:31:59

+0

@Jason查看我的**編輯#1 ** – 2014-11-05 18:42:47

+0

完美,謝謝!我在Target.Copy ...:Sheets(「Detail」)下面添加了一行。激活,希望當選擇了發票#時,工作表也會打開,但它不起作用,有什麼想法? – Jason 2014-11-05 19:00:46