Copy a single selected word in a cell into memory using vba /or sendkeys

Joined
Nov 23, 2023
Messages
6
Office Version
  1. 2016
Platform
  1. Windows
Hi, I have a simple task to do but my attempts seem to just result in pasting a line of vba into the destination cell, instead of the value selected.

You can see in the attached image that I have a button to click on (with attached subroutine), a string of words in one cell, only one of which is selected, and a destination cell.
Now, I can press CTRL+C with my left hand before clicking the button (with a paste script) to achieve this.
However as I expect to do this many times, I wish for a script that will accomplish the CTRL+C part and allow me to paste the selected word in one click.

I have tried using SendKeys but its not working correctly. As you can see in this example, instead of pasting "primary", it pasted a vba code line "Application.SendKeys"

Copy Problem.JPG


Does anyone have any scripting knowledge that can make this work ? Any advice is greatly appreciated :)

Bob
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
If you select a cell with the text of which you want a specific word copied, you could do this if it suits you.
Have a button on the sheet with following code assigned to it:
Code:
Sub Lets_Do_It()
UserForm1.ListBox1.List = Split(ActiveCell.Value, " ")
UserForm1.Show
End Sub
Have a UserForm named "UserForm1" with a ListBox named "ListBox1" (Both names without double quotes)
In the UserForm Module, put this code. Change reference (Offset(, 2)) as required.
Code:
Private Sub ListBox1_Click()
ActiveCell.Offset(, 2).Value = ListBox1
Unload Me
End Sub
When a cell with the text is selected, click on the macro button and select the word that needs to be copied from the ListBox.
 
Upvote 0
Solution

Forum statistics

Threads
1,223,883
Messages
6,175,168
Members
452,615
Latest member
bogeys2birdies

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