Consulting

Results 1 to 6 of 6

Thread: Can we write both in left and right alignment in same cell?

  1. #1
    VBAX Contributor
    Joined
    Jun 2006
    Posts
    135
    Location

    Can we write both in left and right alignment in same cell?

    Hi,

    I have some cells in which I write long texts at first, and the width of this column is set so as to be just one A4 page.


    Below this, I want to write 2 things separately, so I used 2 columns, but then the second one is not on the same page when I print.
    Can I write the second thing at the right of the big cell, even if there is something in the left? (Both are short enough and they will never collide).
    Or can I separate a cell in 2, where I would put one of each? The problem is that I can't do that manually because the row index when the second part starts may vary, and I want that the next time I run the program it is again one single row (because the first list could be longer)

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    You might try using 2 columns all the way down and set your print area to the 2 columns. In the first instead of merging the 2 columns you can format them to center across selection which has the same effect(appearance) as merging the cells but there is no merge...the two cells are still in place.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    VBAX Contributor
    Joined
    Jun 2006
    Posts
    135
    Location
    And how am I supposed to do this?

    I tried to copy like that:

    [VBA]Range(Cells(k, 2), Cells(k, 3)).Select
    ActiveSheet.Paste[/VBA]

    But it doesn't work. It copys the text in each one of the cells (I would need it only once but all over the 2 cells.

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I just recorded the steps with the recorder to get this:
    [VBA]Sub Macro1()
    Range("E5").Select
    ActiveCell.FormulaR1C1 = "This is a test"
    Range("E5:F5").Select
    With Selection
    .HorizontalAlignment = xlCenterAcrossSelection
    .VerticalAlignment = xlBottom
    .WrapText = False
    .Orientation = 0
    .AddIndent = False
    .IndentLevel = 0
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .MergeCells = False
    End With
    Range("G18").Select
    End Sub[/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  5. #5
    VBAX Contributor
    Joined
    Jun 2006
    Posts
    135
    Location
    Thanks, but I was more looking for something like
    .HorizontalAlignment = xlLeftAcrossSelection

    Doesn't it exist?

  6. #6
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Jungix,
    I made up this KB item http://vbaexpress.com/kb/getarticle.php?kb_id=481 to split long text into separate rows, which may suit your purpose. Try using 0.46 as the ratio, rather than the suggested 0.23, and adjust the column widths to suit.
    Regards
    MD
    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
  •