Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am copying individual cells from excel and pasting it into SQL. Each time I do it, carriage return is automatically added to copy.

Repro:

Enter 123 in any cell in excel 2007.Click on another cell. Now right click on the cell you just entered. Select copy. Open notepad and paste. Note that carriage return is also copied, where there is no carriage return in the cell.

share|improve this question

1 Answer 1

I believe you'd want the carriage return if you were copying more than one cell, which is probably why it's being included.

But if you're copying one at a time, you can copy from the formula bar instead of from the cell then you won't get the carriage return.

If you have a lot of cells to copy, you might want to create a simple VBA script to push the contents of the selected cell into the clipboard (then assign that to a hotkey).

Edit:

Example macro:

Sub CopyActiveCell()
    Dim objData As MSForms.DataObject
    Set objData = New MSForms.DataObject
    objData.SetText ActiveCell.Value
    objData.PutInClipboard
End Sub

Note that for that to work you need to add a reference to Microsoft Forms 2.0 Object Library (via Tools | References). If you're copying many values, you could make it even simpler by adding creating the sub in the Sheet1 module as

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

instead of

Sub CopyActiveCell()

That will automatically copy the cell value whenever you click once on a cell to select it.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.