ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   command button sub (https://www.excelbanter.com/excel-discussion-misc-queries/220345-command-button-sub.html)

Atishoo

command button sub
 
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

Jim Thomlinson

command button 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
--
HTH...

Jim Thomlinson


"Atishoo" wrote:

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


Sheeloo[_3_]

command button 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...

"Atishoo" wrote:

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


Atishoo

command button sub
 
thank you!!

"Jim Thomlinson" wrote:

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
--
HTH...

Jim Thomlinson


"Atishoo" wrote:

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



All times are GMT +1. The time now is 08:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com