Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Worksheet temperamental about centering

Status
Not open for further replies.

UnsolvedCoding

Technical User
Jul 20, 2011
424
0
0
US
I can't figure this one out. I have three different sets of code that is simply to center text in cells. When either of the first two are run in the sub or the immediate window it doesn't work and returns null.

Code:
?ThisWorkbook.Sheets("Grouping").Cells.HorizontalAlignment = xlCenter
Null

?Cells.HorizontalAlignment = xlCenter
Null

But when I recorded a macro and ran that code (below) it worked fine. Why?

Code:
Sub Macro1()
'
' Macro1 Macro
'

'
    Cells.Select
    With Selection
        .HorizontalAlignment = xlCenter
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    Range("A1").Select
End Sub

It has taken me a while to make sense of what I hear at work involving computers. There is much talk of bugs and questions about Raid.
Therefore I have come to the logical conclusion that the only way to have a properly functioning computer is to regularly spray it with Raid bug killer.
 
So, I had Excel freeze on me for no apparent reason and ended up shutting off the computer for a few minutes and now all three snippets of code work fine.

It has taken me a while to make sense of what I hear at work involving computers. There is much talk of bugs and questions about Raid.
Therefore I have come to the logical conclusion that the only way to have a properly functioning computer is to regularly spray it with Raid bug killer.
 
?" in Immediate window is a command to print what is after it, here if horizontal alignment is set to xlCenter. To set something here just skip the question mark.
You are trying to format over 16 bilions of cells, so it takes some time...

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top