PDA

View Full Version : Solved: Macro: Cell Formatting is Failing



YellowLabPro
03-04-2007, 01:40 PM
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


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

Simon Lloyd
03-04-2007, 02:16 PM
Hi here's what i recorded changing column width, row height, Font to 16 bold and horizontal text centre aligned.

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
Regards,
SImon

Norie
03-04-2007, 02:25 PM
Try replacing Selection with rng.

YellowLabPro
03-04-2007, 02:45 PM
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