+ Reply to Thread
Results 1 to 6 of 6

Copying two-line cell WITH column width auto-adjustment?

  1. #1
    Registered User
    Join Date
    04-02-2009
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    40

    Copying two-line cell WITH column width auto-adjustment?

    Assume I have a cell with a column width of lets say 15 centimeters and a row high of two lines.
    The content of this cell are two text lines separated by a newline/Carriage return like


    blah blah blah 12345 foo bar
    next, second line text


    Now I mark this cell and choose "copy" from context menu. A dotted line appears around the cell indicating that the cell content is copied into clipboard. Fine.

    Now I switch to another worksheet, put the cursor in one of the (standard formatted) cells and select "Paste" from context menu.

    The content is copied BUT:
    the column width stay as before. This in turn causes the row height to increase to more than two lines. It looks similar to


    blah
    blah
    blah
    12345
    foo bar
    next,
    second
    line
    text

    How can I let Excel auto-adjust the column width according to the source column width? ....and prevent row height adjustment?

    BTW: This solution should work as well if I select a whole region with different cell/columns widths.

    Related question: Assume I want to achieve this not by manually, visual copy&paste but from VBA macro.
    How should a macro command look like which pay attention to this auto-adjustment?

    Peter
    Last edited by pstein; 11-30-2014 at 04:15 AM.

  2. #2
    Forum Expert Crooza's Avatar
    Join Date
    10-19-2013
    Location
    Hunter Valley, Australia
    MS-Off Ver
    Excel 2003 /7/10
    Posts
    2,082

    Re: Copying two-line cell WITH column width auto-adjustment?

    Not sure where you want to copy to but let's assume you want to select the cell of your choosing and paste to a given cell f1

    This will take your selection , copy it then set the column width to the same as the cell you copied from. You shouldn't need to worry about the cell hieghts but if you do you can use the same syntax

    Please Login or Register  to view this content.
    Happy with my advice? Click on the * reputation button below

  3. #3
    Registered User
    Join Date
    04-02-2009
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    40

    Re: Copying two-line cell WITH column width auto-adjustment?

    Ok, thank you.

    Is there a way of doing this visually (=NOT by VBA script)?

  4. #4
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Copying two-line cell WITH column width auto-adjustment?

    Yes, but clumsy. After coying select "Paste Special" and selct value, then do another "Paste Special" and then selcet "Column Withs"

    Alf

  5. #5
    Registered User
    Join Date
    04-02-2009
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    40

    Re: Copying two-line cell WITH column width auto-adjustment?

    @Alf: Great! Thank you.

    But why does "Paste Special" with ticked "All" not copy values AND column widths as it implies?

    Is this a bug?

    And one more question: Assume I want to copy the format (e.g. boldface text) as well.
    what is the appropriate VBA command therefore?
    In other words: What is the equivalent of

    X=selection.columnwidth
    ....
    .....
    Selection.columnwidth =x

    for format?

    Y=Selection.formats
    ....
    Selection.formats=y

    does not work.

  6. #6
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Copying two-line cell WITH column width auto-adjustment?

    Is this a bug?
    Not as far as I know. I have no idea why neither column width nor row height are not included in the "PasteSpecial Paste All"
    As for copying using VBA perhaps this example will explain it a bit better
    Please Login or Register  to view this content.
    The command "xlPasteValues" will paste "bold" , "Italics" or "Underline" if the Copy from cell contains any of these settings. You could also use
    Please Login or Register  to view this content.
    but to get the column width you must add the "PasteSpecial xlPasteColumnWidths" command.
    Another useful comand is the
    Please Login or Register  to view this content.
    This will set the "right" column width on all columns that contain a value.
    Alf
    Last edited by Alf; 12-14-2014 at 04:53 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Column Width Adjustment
    By JerryA in forum Excel General
    Replies: 3
    Last Post: 04-11-2006, 08:35 PM
  2. [SOLVED] Automatic column width adjustment
    By Senator in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-03-2005, 04:05 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1