Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default Centering Text Not Working

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Centering Text Not Working

It's the range that has the .horizontalalignment property:

Option Explicit

Private Sub AAA1_Click()
With Range("A1")
If .Value = 1 Then
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
'you change it to 1 later????
.Interior.ColorIndex = 3
.Font.Bold = True
With .Interior
.ColorIndex = 1
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Else
With .Interior
.ColorIndex = 29
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
End If
End With

End Sub

caldog 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


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 139
Default Centering Text Not Working

caldog:

With Selection
.HorizontalAlignment = xlCenter '- "Line not working"
.VerticalAlignment = xlCenter '-"Line not working"
.Font.ColorIndex = 3
.Font.FontStyle = "Bold"
End With

--
天行健,君*以自強不息
地勢坤,君*以厚德載物

http://www.vba.com.tw/plog/


"caldog" 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default 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
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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default Centering Text Not Working

To Chijanzen, Dave Peterson, & Gord

Thanks for your replys. You supplied me with the answers that I need.

May all of you have a great holiday season.

Steve

"Gord Dibben" wrote:

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
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




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Centering Text Not Working

Thanks for the feedback and Happy Holidays to you and yours from all of us.

Gord

On Tue, 20 Dec 2005 16:58:02 -0800, caldog
wrote:

To Chijanzen, Dave Peterson, & Gord

Thanks for your replys. You supplied me with the answers that I need.

May all of you have a great holiday season.

Steve

"Gord Dibben" wrote:

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
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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Centering text in right-side header block standard_guy Excel Discussion (Misc queries) 1 May 6th 10 12:43 AM
Cell Text Alignment - Not A Centering Issue Minitman Excel Discussion (Misc queries) 4 July 14th 08 08:42 AM
Centering MsgBox text Patrick Excel Programming 2 February 17th 05 07:49 PM
Centering the text in a message box Rob_T Excel Programming 2 October 10th 04 01:12 AM
Centering the text in a message box Rob_T Excel Programming 4 October 8th 04 10:02 AM


All times are GMT +1. The time now is 04:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright 2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"