I have a worksheet that contains invoice numbers in column D. I'd like to copy the invoice number to another worksheet ("Details") when one is selected. I've added the "If IsNumeric" condition to make sure that only cells containing an invoice # will be copied over. The code seems to do nothing, can anyone help point me in the right direction?
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
Rather than:
IsNumeric(Target.Address)
try
IsNumeric(Target)
EDIT#1:
Try this:
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
EDIT#2:
You need to re-enable events within the same 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.