Re: Centering Text Not Working



Steve

Font doesn't have an alignment property.

You can End With after the 2 alignment lines and then start another With
statement for the Font or just amend as follows.

Private Sub AAA1_Click()

If Range("A1") = 1 Then
Range("A1").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.Font.ColorIndex = 3
.Font.FontStyle = "Bold"
End With
With Selection.Interior
.ColorIndex = 1
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Else
Range("A1").Select
With Selection.Interior
.ColorIndex = 29
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
End If
End Sub


Gord Dibben Excel MVP

On Tue, 20 Dec 2005 15:48:02 -0800, caldog <caldog@xxxxxxxxxxxxxxxxxxxxxxxxx>
wrote:

>I have this code that bolds and that puts color as background if certain
>conditions are met. What is not happening is that the text centering line is
>erroring out. Can somebody explain why this is.
>
>Steve
>
>Private Sub AAA1_Click()
>
>If Range("A1") = 1 Then
> Range("A1").Select
> With Selection.Font
> .HorizontalAlignment = xlCenter - "Line not working"
> .VerticalAlignment = xlCenter - "Line not working"
> .ColorIndex = 3
> .FontStyle = "Bold"
> End With
> With Selection.Interior
> .ColorIndex = 1
> .Pattern = xlSolid
> .PatternColorIndex = xlAutomatic
> End With
>Else
> Range("A1").Select
> With Selection.Interior
> .ColorIndex = 29
> .Pattern = xlSolid
> .PatternColorIndex = xlAutomatic
> End With
>End If
.



Relevant Pages

  • Re: Centering Text Not Working
    ... To Chijanzen, Dave Peterson, & Gord ... > Font doesn't have an alignment property. ... > Private Sub AAA1_Click ... > .Pattern = xlSolid ...
    (microsoft.public.excel.programming)
  • Re: Speaking of fonts--- and new businesses and such--
    ... diagrams I want to include in the instructions, sigh, and the $$$ to get ... about $60 and you can even get your pattern package (cover, ... if you have a suggestion of a font please let me know. ... Pati, in Phx ...
    (rec.crafts.textiles.quilting)
  • RE: Help with events
    ... Private Sub Worksheet_SelectionChange ... ' Auto Data update macro ... .Pattern = xlSolid ...
    (microsoft.public.excel.programming)
  • Speaking of fonts--- and new businesses and such--
    ... As some of you know I am in the process of trying to get a pattern company going. ... And I need to decide on a font to use for my pattern covers. ... but I've got GREAT font sites - free fonts that are just awesome! ...
    (rec.crafts.textiles.quilting)
  • Bug in GDI whit zoom
    ... I have found a probable bug when you draw with GDI. ... Private Sub Form1_PaintHandles MyBase.Paint ... e.Graphics.ScaleTransform(Zoom, Zoom) ... With personal Pattern you must do this to have the desired pattern ...
    (microsoft.public.win32.programmer.gdi)