command button sub

A

Atishoo

Hi why wont this work for a command button, what should I write instead?

Private Sub CommandButton3_Click()

If Not Intersect(Target, Range("patientlist")) Is Nothing Then
UserForm2.TextBox1.Value = ActiveCell.Value
UserForm2.Show
End If

End Sub
 
J

Jim Thomlinson

What is target? Event subs have target as a parameter. Yours does not define
target anywhere. Perhaps activecell

Private Sub CommandButton3_Click()

If Not Intersect(activcell, Range("patientlist")) Is Nothing Then
UserForm2.TextBox1.Value = ActiveCell.Value
UserForm2.Show
End If

End Sub
 
S

Sheeloo

This code should go into Worksheet_Change(ByVal Target As Range) or
Worksheet_SelectionChange(ByVal Target As Range) events.

Test what the 'Target' is when you click on the button...
 
A

Atishoo

thank you!!

Jim Thomlinson said:
What is target? Event subs have target as a parameter. Yours does not define
target anywhere. Perhaps activecell

Private Sub CommandButton3_Click()

If Not Intersect(activcell, Range("patientlist")) Is Nothing Then
UserForm2.TextBox1.Value = ActiveCell.Value
UserForm2.Show
End If

End Sub
 
Top