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
 
hrmmm.... I seem to be getting this now:

Untitled.png
 
Upvote 0

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
If you just want to copy the selected cell's contents to the Windows clipboard

Code:
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

This works for me and I can then select another application (Notepad) and paste.
 
Upvote 0
I had to re-insert the userform to get the script running with reference to microsoft forms 2.0 library. For some reason though, it's not copying any cells I select.
 
Last edited:
Upvote 0
This is really frustrating... Why does excel keep creating a new code template over the one I pasted after hitting run.
 
Upvote 0
You should not need to "run" anything. That is event code - it runs automatically when you change the selection on any sheet.
 
Upvote 0
This is more reliable - double click a cell to add to the Windows clipboard. Again no need to run anything


Code:
Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
Dim DataObj As New MSForms.DataObject
Dim S As String
If Intersect(Target, Range("A1:J281")) Is Nothing Then Exit Sub
Cancel = True
S = Target.Text
DataObj.SetText S
DataObj.PutInClipboard
End Sub
 
Upvote 0
ahhhh..... okay thanks for clarifying that, the clicking on "run" was totally messing me up.

I pasted the new code and tried double clicking on a cell.. no go.

Sorry to be picky but I need it to be single click if possible.
 
Upvote 0
Thanks for your help man, I really appreciate it. I messed around with the code some more and I'm finding when I paste:

Sub Worksheet_SelectionChange(ByVal Target As Range) 'single click version

If Intersect(Target, Range("A1:J281")) Is Nothing Then Exit Sub
ActiveCell.Copy

End Sub

It works but won't paste properly into the other program I'm pasting it into.

When I tried your code (With user module inserted and MS Forms 2.0 library selected for reference):

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

Nothing happens, I can't seem to figure out what I'm missing especially if you say it's working on your system.

I just need something that will allow me to single click a cell, copy text ONLY from the cell that was clicked and paste it into VCI Orion program I use at work. For some reason if I try to copy paste directly from excel it won't work but if I copy paste text from notepad it's fine.

The only way it seems to work from excel is if I triple click the cell, highlight the text and THEN copy into VCI Orion program - but I'm trying to cut it down to just single click and paste.

Thank you for your help regardless though man I learned a lot and I really appreciate your patience with me. lol, Cheers!
 
Last edited:
Upvote 0
Hi Again guys,

I'm still struggling with the code in previous posts, the original code from the very first thread post works but I need it to paste text ONLY.

Is there anyone out there who can write me a code that will copy text ONLY using a single click from any cell selected in a spread sheet? It must ONLY copy text, otherwise it won't paste it into the finicky program I'm forced to use at work.

I'm in desperate need of this and any help would be greatly appreciated, thanks again.
 
Upvote 0

Forum statistics

Threads
1,225,190
Messages
6,183,457
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