Copy just contents of a cell without a carriage return?

Mitchell

New Member
Joined
Mar 20, 2007
Messages
40
Office Version
  1. 2003 or older
Platform
  1. Windows
This is something I've run into every time I have had a macro that copies cell contents: when one goes to paste the text, a hard return is added to the text, which makes copying into fields a pain.

VBA Code:
    ActiveSheet.Range("A1").Select
    Selection.Copy

How can one have just the text copied without adding a carriage return, please?

Thank you!
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Please see post below, I thought I was editing this post but now it is a permanent fixture...
VBA Code:
ActiveSheet.Range("A1").Copy
 
Last edited:
Upvote 0
when one goes to paste the text, a hard return is added to the text, which makes copying into fields a pain.
I don't understand what you are saying here, but can't you just use this line...
VBA Code:
ActiveSheet.Range("A1").Copy
 
Upvote 0
I don't understand what you are saying here, but can't you just use this line...
VBA Code:
ActiveSheet.Range("A1").Copy

Sorry I didn't explain well. I should have included an example no matter how straightforward the problem is. Sorry about that.

Thanks for the shorter code. It does exactly the same thing (hence the same problem), but nice to have 1 line of code instead of 2.

The script, unfortunately, does the same thing and tacks on a carriage return to the result. So this code copies the target cell contents but adds a hard return to the result which creates a problem if you're copying directly into a, say, field, which accepts only 1 line of text and no carriage returns.

This all results in fiddling with the end result, which is extremely frustrating, esp. since I need to create an Excel sheet this time around that has different cells to copy from for different concatenated source text. So this solution would save even more time if it was clean and required no fiddling with the end result.

To illustrate, let's say I'm copying the following text below from A1 (this is just an example). The text in question is illustrated by what is in the square brackets (in other words, hope that it illustrates that the text being copy/pasted is what is in between the square brackets, only:

[2023-07-19.Wed]

I get this, however, with tacked-on carriage return:

[2023-07-19.Wed
(a carriage return here)]

so that instead of a single line, I get 2 lines with the carriage return.

Any help appreciated in this regard. Thank you!
 
Last edited:
Upvote 0
Given what seems to be a unique issue, we would probably have to see more of your code along with some representative data (real or fictitious), preferably using XL2BB. It would also be helpful if you could finish your profile so the community knows what version of Excel you are using and on what platform..
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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