Copy from Excel and Paste in external app?

jmpatrick

Active Member
Joined
Aug 17, 2016
Messages
482
Office Version
  1. 365
Platform
  1. Windows
Good morning!

Here's today's issue: I'm copying from a cell in Excel to another app. I'm getting a trailing carriage return when I paste in Notepad, Word, and Adobe Acrobat.

copy.png


Result:

paste.png


If I copy the text D10 and paste it in E10 I can get the value up in the Formula Bar. If I copy the text in the Formula Bar I can paste it anywhere without the trailing carriage return. Is it possible to copy the formula using VBA?

copy2.png
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Did you try expanding row 10 height 2 or 3 times what it is and see what happens if you click below the visible value? Your cell values just might contain trailing character(s) that create a new line. That would suggest the values come from another source although you didn't say they do. If it is as I describe, the right choice is probably to remove the trailing characters instead. That can be done via vba also.
Is it possible to copy the formula using VBA?
What's in the formula bar doesn't look like a formula to me. :unsure:
 
Upvote 0
Did you try expanding row 10 height 2 or 3 times what it is and see what happens if you click below the visible value? Your cell values just might contain trailing character(s) that create a new line. That would suggest the values come from another source although you didn't say they do. If it is as I describe, the right choice is probably to remove the trailing characters instead. That can be done via vba also.

What's in the formula bar doesn't look like a formula to me. :unsure:

Correct no formula in the formula bar, but it has the text I need to paste and when I copy it from there and paste it externally it works correctly.
 
Upvote 0
If you copy a single line from the formula bar you probably won't copy the line feed characters if they are there. That's why I suggested to increase the row size and look for them as described.
 
Upvote 0
If you copy a single line from the formula bar you probably won't copy the line feed characters if they are there. That's why I suggested to increase the row size and look for them as described.

I checked. No extra characters in the cell. Is there a way to copy from the formula bar using VBA?
 
Upvote 0
Sorry, not sure. Perhaps this
although you might get away with using Trim function on the cell contents. If you want to post a wb copy somewhere I'll see what I can do. You can remove everything private that is not required and just leave enough in to replicate the issue.
 
Upvote 0
You could try the following code. It works for me on the cells with a concatenate formula. Change "Sheet1.Range("D1:D50")" to match the range that you want to be copied. The idea is that when you select that cell, the text value of the cell will be copied to the clipboard.

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

    If Not Intersect(Target, Sheet1.Range("D1:D50")) Is Nothing Then
        With New DataObject
            .SetText Target.Text
            .PutInClipboard
        End With
    End If

End Sub

Hope that helps,

Doug
 
Upvote 0
You could try the following code. It works for me on the cells with a concatenate formula. Change "Sheet1.Range("D1:D50")" to match the range that you want to be copied. The idea is that when you select that cell, the text value of the cell will be copied to the clipboard.

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

    If Not Intersect(Target, Sheet1.Range("D1:D50")) Is Nothing Then
        With New DataObject
            .SetText Target.Text
            .PutInClipboard
        End With
    End If

End Sub

Hope that helps,

Doug

Thanks, Doug. Using your code I'm getting this error:

cop3.png
 
Upvote 0
Sorry, in VBA editor, Tools, References, put a check by "Microsoft Forms 2.0 Object Library".

Doug
 
Upvote 0

Forum statistics

Threads
1,223,247
Messages
6,171,007
Members
452,374
Latest member
keccles

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