command button sub

  • Thread starter Thread starter Atishoo
  • Start date Start date
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
 
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
 
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...
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top