Copy Cell Content on Click

excelnow

Board Regular
Joined
Nov 17, 2009
Messages
106
Hi,

I am not sure if this is possible because I couldn't find anything about this on the web and on this forum.

I want to copy the cell content(text) when I click on it. Can this be done via code?

Thanks
 
Anyone else been able to get this code working?

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
If Intersect(Target, Range("A1:J281")) Is Nothing Then Exit Sub
Dim DataObj As New MSForms.DataObject
Dim S As String
S = Target.Text
DataObj.SetText S
DataObj.PutInClipboard
End Sub
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hi Again guys,

I managed to get a working code from a different source, here it is in case anyone out there needs it:


Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
If Intersect(Target, Sh.Range("A1:J281")) Is Nothing Then Exit Sub
Dim DataObj As Object
Dim S As String
Set DataObj = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
S = ActiveCell.Text
DataObj.SetText S
DataObj.PutInClipboard

End Sub

Thanks again everyone for your time & help, it's very much appreciated!
 
Upvote 0
Hi again guys,

After much use of the one-click copy text only macro script, I'm realizing it would be more efficient to use arrow keys to select and copy text only rather than single clicking. So would it be possible to modify the script to copy text only using any arrow key? ie: what ever cell is selected after hitting any arrow key it lands on will have text only copied instead of the click?

Here's the code again:

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)

If Intersect(Target, Sh.Range("A1:J10000")) Is Nothing Then Exit Sub

Dim DataObj As Object
Dim S As String
Set DataObj = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
S = ActiveCell.Text
DataObj.SetText S
DataObj.PutInClipboard

End Sub

Thanks so much in advance any help would be greatly appreciated.
 
Upvote 0
Hello!

Sorry for reopening this.
This code

Sub Worksheet_SelectionChange(ByVal Target As Range) 'single click version If Intersect(Target, Range("B2:G10")) Is Nothing Then Application.CutCopyMode = False 'clears clipboard and stops cell flashing - like pushing escape key Exit Sub Else ActiveCell.Copy End If End Sub</pre>

Works excellent for me.
But the cells that I'm copying contains multi-lines and when I paste, what I get is a text within quotes.
Is there a way to modify the strings contained in the Clipboard to delete all these quotes?

Thanks.
 
Upvote 0

Forum statistics

Threads
1,225,190
Messages
6,183,459
Members
453,160
Latest member
DaveM_26

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