Consulting

Results 1 to 4 of 4

Thread: Solved: Macro: Cell Formatting is Failing

  1. #1

    Solved: Macro: Cell Formatting is Failing

    [VBA]
    Sub AlignGrid()
    '
    ' To center sizing matrix
    ' Macro recorded 3/4/2007 by Doug Stroud
    '
    '
    Dim rng As Range
    Dim i As Long
    Set rng = Application.InputBox("Select range with the mouse", Type:=8)
    With Selection
    .HorizontalAlignment = xlGeneral
    .VerticalAlignment = xlCenter
    .Name = "Arial"
    .Font.Size = 10
    .Font.Bold = False
    .WrapText = False
    .Orientation = 0
    .AddIndent = False
    .IndentLevel = 0
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .ColumnWidth = 3
    .RowHeight = 12.75
    End With
    End Sub
    [/VBA]

    Some of the cell properties are failing to change from the above code, specifically, ColumnWidth, RowHeight, Size, Font.Bold, Name, Horizontal.
    Is my code setup incorrectly?

    Thanks,

    YLP

  2. #2
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Hi here's what i recorded changing column width, row height, Font to 16 bold and horizontal text centre aligned.
    [VBA]
    Sub Macro1()
    Columns("A:A").Select
    Selection.ColumnWidth = 10
    Rows("1:1").Select
    Selection.RowHeight = 15
    With Selection
    .HorizontalAlignment = xlGeneral
    .VerticalAlignment = xlCenter
    .WrapText = False
    .Orientation = 0
    .AddIndent = False
    .IndentLevel = 0
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .MergeCells = False
    End With
    With Selection.Font
    .Name = "Arial"
    .FontStyle = "Bold"
    .Size = 16
    .Strikethrough = False
    .Superscript = False
    .Subscript = False
    .OutlineFont = False
    .Shadow = False
    .Underline = xlUnderlineStyleNone
    .ColorIndex = xlAutomatic
    End With
    [/VBA]Regards,
    SImon
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Try replacing Selection with rng.

  4. #4
    Bravo Norie,
    That did the trick, thanks.

    Simon, I was working on removing the non-essiental lines from the macro. Norie pointed out that the variable was the problem.


    Thank you,

    YLP

Posting Permissions

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