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
 
hrmmmmm...... okay, assuming what I pasted before was correct this is what I tried with your suggestion:


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

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

Dim DataObj As New MSForms.DataObject
Dim S As String
S = "ActiveCell.Text"
DataObj.SetText S
DataObj.PutInClipboard

Dim DataObj As New MSForms.DataObject
Dim S As String
DataObj.GetFromClipboard
S = DataObj.GetText
Debug.Print S

End Sub


Still not working unfortunately. This is so frustrating, I'm positive there has to be a way because I'm able to copy and paste text directly from notepad so if it works on notepad, why isn't it working for excel. grrrrrrr.....

Thanks again btw Mr Excel, if you have any other suggestions please feel free to share.
 
Upvote 0

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
hrmmm..... okay, newbie question. what I'm doing is opening up the Visual Basic editor/view code/paste code into code field/clicking run but every time I do that it opens up a macro window asking me to name and create a new one. When I click create, it adds the following code to end of what I pasted:

Sub workbook()

End Sub

-The script still runs though, does this make a difference?

I ran the following inspite of the above and got the same results:

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

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

Dim DataObj As New MSForms.DataObject
Dim S As String
S = ActiveCell.Text
DataObj.SetText S
DataObj.PutInClipboard

Dim DataObj As New MSForms.DataObject
Dim S As String
DataObj.GetFromClipboard
S = DataObj.GetText
Debug.Print S

End Sub
 
Upvote 0
It should be

Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
'
'your code here
'
End Sub

which has to go in the ThisWorkbook module.
 
Upvote 0
It should be

Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
'
'your code here
'
End Sub

which has to go in the ThisWorkbook module.
hrmmmm..... I seem to now be getting the following error:

"Compile error:

Procedure declaration does not match description of event or procedure having the same name."

I tried googling this and they say it could possibly be a windows 7 thing? argh, so frustrating.

http://social.msdn.microsoft.com/Fo...s/thread/3a4ce946-effa-4f77-98a6-34f11c6b5a13
 
Upvote 0
Where did you put the code? Press ALT + F11 to open the Visual Basic Editor, in the Project window double click ThisWorkbook then paste in the code.
 
Upvote 0
in the project window I double clicked "ThisWorkbook" and pasted the following:

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 = ActiveCell.Text
DataObj.SetText S
DataObj.PutInClipboard

Dim DataObj As New MSForms.DataObject
Dim S As String
DataObj.GetFromClipboard
S = DataObj.GetText
Debug.Print S

End Sub

End Sub
 
Upvote 0
The following line is highlighted in yellow with an arrow pointing to it on the far left side:

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

Forum statistics

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