Consulting

Results 1 to 3 of 3

Thread: Paste Multiple lines into single Cell

  1. #1
    VBAX Newbie
    Joined
    Nov 2009
    Posts
    2
    Location

    Lightbulb Paste Multiple lines into single Cell

    I manually am copying multiple line text from VBE Modules (comments) and paste into a single cell in Excel. See the steps:
    In VBE Modules select multiple lines.
    Copy
    In Excel: Select a cell, press {F2} and paste.
    How can I write a code to edit Cell {F2} and paste?
    I tried the follow and did not work (it pasted to multiple cell instead a single cell)

    Sub EditPaste()
    'Edit Cell and Paste whatever is in the Clipboard.and UnWrap
    ActiveCell.Select
    Application.SendKeys "{F2}"
    ActiveSheet.Paste
    Application.Run "PERSONAL.XLSB!UnWrap"
    End Sub

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    maybe:
    [VBA]
    ActiveCell.FormulaR1C1 =
    [/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Try this
    [VBA]
    Sub AllInOne()
    Dim i As Long, txt As String
    ActiveSheet.Paste
    For i = 1 To Selection.Cells.Count
    txt = txt & Selection(i) & Chr(10)
    Next
    Selection.ClearContents
    Selection(1) = txt
    End Sub

    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •