• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Pass selected text with the mouse from one Textbox to another

Visor

Member
Greetings friends of the forum, as you will see I have tried in several ways to make what you select with the mouse the macro copy it and pass it from Texbox1 to Texbox2
I upload the file so you can see it, I also show an image that as an example I selected a part of the Texbox1. If I click on the down arrow button it should go through only the selected part
Thank you in advance for your support
 

Attachments

  • Pasar el texto seleccionado en textbox a otro.xlsm
    31.1 KB · Views: 5
  • seleccion de texto.jpg
    seleccion de texto.jpg
    122.6 KB · Views: 6
Paste this macro into the UserForm :

Code:
Private Sub TextBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
TextBox2.Text = TextBox1.Text
End Sub

Whenever you double-click on TextBox1 it will transfer the text to TextBox2.

Of course you can add to the macro by deleting the existing text in TextBox1 after it has been transferred to TextBox2.

You can also add the code to the CommandButton click event. Instead of double-clicking the textbox, you will simply click the CommandButton.
 
Hi Visor
Is this what you looking for?
Put this code in your transfer button.
Select the part of text you want in textbox 1 and push your transfer button.
Only selected part will be tranfered to textbox 2
Code:
Private Sub CopiarATbx2_Click()
Dim Texto As DataObject
    Set Texto = New DataObject
        Texto.SetText TextBox1.SelText
        Texto.PutInClipboard
    TextBox2.Paste
End Sub
 
Thank you Logit for your support, but it is not how the macro looked to work.
Thanks Belleke is just what I wanted, so only what I select in Textbox1 transfer to Textbox2.
It's great.
Because what ultimately transpires is Textbox2.paste
Try to delete from Textbox1 what has been transferred
using Textbox1.clear.
It does not work.
How could I do so that what has been transferred is removed from textbox1?
I am very grateful
 
Set the button's TakeFocusOnClick property to False and then just change its code to this:

Code:
Private Sub CopiarATbx2_Click()
    Me.TextBox1.Cut
    Me.TextBox2.Paste
End Sub
 
Hi Visor,
IS this what you looking for?
Code:
Private Sub CopiarATbx2_Click()
Dim Texto As DataObject
    Set Texto = New DataObject
        Texto.SetText TextBox1.SelText
        Texto.PutInClipboard
    TextBox2.Paste
      TextBox1.SelText = ""
End Sub
If you also want the cell text changed , then add
Code:
[B4] = TextBox1
 
Last edited:
Dear Debase, I greatly appreciate a simplified code, or short code that does what you expect, thank you very much.
Dear Belleke, with this I complete the code thanks for the support, when adding the code.
I'm very grateful
Solved theme
 
Back
Top