none
Please Help Me????

    Question

  • I do not understand to do this Exam??? please tell me step by step....
    1. In the Order Form worksheet, create a macro that formats the Column Width to e exactly 20 pixels and applies the middle align format to the cell contents. Name the macro Width and store it in only this workbook. (Note: accept all other default settings)
    Friday, May 6, 2016 12:08 AM

Answers

  • Here's the correct code:-

    Sub Width()
    '
    ' Width Macro
    '

    '
        Columns("A:A").ColumnWidth = 2.14
        With Selection
            .HorizontalAlignment = xlGeneral
            .VerticalAlignment = xlCenter
            .WrapText = False
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
    End Sub

    In the exam the user would be required to achieve the above by making the selections in the GUI and then saving the macro.

    Sunday, May 8, 2016 3:34 PM

All replies

  • Hi, Js.

    You probably want to do something similar to the code below.

    Note that this was just grabbing column "A".

    Sub Width()
      Columns("A:A").ColumnWidth = 20
      Columns("A:A").HorizontalAlignment = xlCenter
    End Sub

    Good luck!


    Best wishes, Davin Mickelson

    Friday, May 6, 2016 1:48 AM
    Answerer
  • Davin - I reckon that fails testing.

    After running your code column width is set to:-

    Width: 20.00 (145 pixels) [user wanted 20 pixels]

     - and your second line of code fails to set the Middle Align at all (it doesn't change it).

    Note to Js Thao:-

    You need to post here:-

    http://answers.microsoft.com/en-us/office/forum/excel?sort=lastreplydate&dir=desc&tab=threads&status=unanswered&mod=&modAge=&advFil=&postedAfter=&postedBefore=&threadType=questions&tm=1462707900036

     - to get answers to EXCEL questions.


    Sunday, May 8, 2016 2:03 PM
  • Here's the correct code:-

    Sub Width()
    '
    ' Width Macro
    '

    '
        Columns("A:A").ColumnWidth = 2.14
        With Selection
            .HorizontalAlignment = xlGeneral
            .VerticalAlignment = xlCenter
            .WrapText = False
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
    End Sub

    In the exam the user would be required to achieve the above by making the selections in the GUI and then saving the macro.

    Sunday, May 8, 2016 3:34 PM