Removing trailing space when pasting copied information from cell text copied

slayer1957

Board Regular
Joined
Jan 9, 2017
Messages
50
Good day,

I have this code, when clicing a cell it copies to clipboard, it works as it should. However when pasting into any other program it pastes with a space/enter function to all programs. How do i copy and paste without the space at end of the selected cell text.

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Intersect(Target, Range("A1:H50")) Is Nothing Then
        Target.Copy
    End If
End Sub

Also when selecting the text, maybe it should clear previous clipboard?

If anyone knows how on this forum please help, i have tried looking but cannot find code just to remove the space.

Thanks in advance.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
I want the cursor when pasting to end at end of text,
Capture.JPG
and not add to next line like this, each timeI have to press


backspace in the other program pasting to. I have to do more than thousand of copies and pastes.


This it should not do (check the position of cursor on the images
Captureq.JPG
 
Upvote 0
This is so hard, there no solution to this, how can i record a macro, then double click on the cell, select the text and then copy. This works, but how can i record this and then it does this with every cell i click?
 
Upvote 0
See if this does what you need.

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    Dim objClipboard As Object
    
    If Not Intersect(Target, Range("A1:H50")) Is Nothing Then
        Set objClipboard = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
        objClipboard.SetText Target
        objClipboard.PutInClipboard
    End If
End Sub
 
Upvote 1
Solution

Forum statistics

Threads
1,215,071
Messages
6,122,964
Members
449,094
Latest member
Anshu121

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