VBA Code for a command button to copy a text boxes value?

rogersj

Board Regular
Joined
Aug 13, 2002
Messages
187
Could someone post the code? Thanks.

Also, could you post for the button to just select the value in the text box? Thanks in advance!
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Re: VBA Code for a command button to copy a text boxes value

Hey rogersj, The click command for CommandButton1 will copy the value of TextBox1 to my variable myValue. Regards, Marc

Code:
Private Sub CommandButton1_Click()
myValue = TextBox1.Value
MsgBox myValue
End Sub
 
Upvote 0
Re: VBA Code for a command button to copy a text boxes value

Wouldn't

Private Sub CommandButton1_Click()
myValue = TextBox1.Value
MsgBox myValue
End Sub

display a message box with the text box value? I dont need it to copy anymore, I just need the button to select/highlight the text within the text box

Thanks again
 
Upvote 0
Re: VBA Code for a command button to copy a text boxes value

rogersj said:
I dont need it to copy anymore, I just need the button to select/highlight the text within the text box

Thanks again

What part of this is copying? Is there a purpose to select the text in a textbox? What do you want to do with the text after its selected?
 
Upvote 0
Re: VBA Code for a command button to copy a text boxes value

I just want it to select the value, to highlight it. This is for a friend of mine. I dont know why, but this is all he needs done. Thanks for the reply
 
Upvote 0
Re: VBA Code for a command button to copy a text boxes value

rogersj, I believe the code below will perform as you requested. I'm not sure if all of those properties are truly necessary, but it does seem to work. Regards, Marc

Code:
Private Sub CommandButton1_Click()
TextBox1.SelStart = 0       'Indicates the starting point of selected text
TextBox1.SelLength = 500    'number of characters selected in a text box
TextBox1.SetFocus           'Moves the focus to this instance of an object.
TextBox1.Copy               'Copies the contents of an object to the Clipboard.
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,527
Messages
6,114,140
Members
448,551
Latest member
Sienna de Souza

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top