Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Cell alignment centered

Hi everyone,
I have a problem with the cell alignment - the usual routine
".HorizontalAlignment = xlCenter" doesn't work. The font of the cell,
which I want to format is changed, but the alignment is not set. How can
I solve this problem? Thanks for your help, Simon

Code:

'Milestone creation
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
On Error Resume Next
If Not Application.Intersect(Target, Range("D6:D300")) Is Nothing
Then
'Milestone Position
milestone_row = Target.Row
milestone_column = Cells(Target.Row, 2).Value + 11

'Milestone creation
If Target.Value = "M" And Cells(Target.Row, 2).Value 0 Then
If Target.Value < "" Then
Cells(milestone_row, milestone_column).Value = "u"
With Cells(milestone_row, milestone_column).Font
.Color = vbRed
.Name = "Wingdings"
.HorizontalAlignment = xlCenter
End With

Cells(milestone_row, milestone_column + 4).Value =
"Milestone: " & Cells(Target.Row, 1).Value
End If
'Milestone delete
ElseIf Cells(Target.Row, 2).Value 0 Then
Cells(milestone_row, milestone_column + 4).Value = ""
Cells(milestone_row, milestone_column).Value = ""
With Cells(milestone_row, milestone_column).Font
.Color = vbBlack
.Name = "Arial"
.HorizontalAlignment = xlLeft
End With
End If
End If
End Sub

*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Cell alignment centered

Simon,

The alignment property is a property of the range not of the font. So use

With Cells(milestone_row, milestone_column)
.Font.Color = vbRed
.Font.Name = "Wingdings"
.HorizontalAlignment = xlCenter
End With

and similar for the other condition

--
HTH

Bob Phillips

"Simon Fischer" wrote in message
...
Hi everyone,
I have a problem with the cell alignment - the usual routine
".HorizontalAlignment = xlCenter" doesn't work. The font of the cell,
which I want to format is changed, but the alignment is not set. How can
I solve this problem? Thanks for your help, Simon

Code:

'Milestone creation
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
On Error Resume Next
If Not Application.Intersect(Target, Range("D6:D300")) Is Nothing
Then
'Milestone Position
milestone_row = Target.Row
milestone_column = Cells(Target.Row, 2).Value + 11

'Milestone creation
If Target.Value = "M" And Cells(Target.Row, 2).Value 0 Then
If Target.Value < "" Then
Cells(milestone_row, milestone_column).Value = "u"
With Cells(milestone_row, milestone_column).Font
.Color = vbRed
.Name = "Wingdings"
.HorizontalAlignment = xlCenter
End With

Cells(milestone_row, milestone_column + 4).Value =
"Milestone: " & Cells(Target.Row, 1).Value
End If
'Milestone delete
ElseIf Cells(Target.Row, 2).Value 0 Then
Cells(milestone_row, milestone_column + 4).Value = ""
Cells(milestone_row, milestone_column).Value = ""
With Cells(milestone_row, milestone_column).Font
.Color = vbBlack
.Name = "Arial"
.HorizontalAlignment = xlLeft
End With
End If
End If
End Sub

*** Sent via Developersdex http://www.developersdex.com ***



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
Making the text in a cell with a money format centered Wombat Excel Discussion (Misc queries) 6 April 22nd 23 12:12 AM
Cell alignment? Donna Excel Discussion (Misc queries) 0 March 8th 10 03:07 PM
In Cell alignment, how do I update the default vertical alignment How to update default cell alignment Setting up and Configuration of Excel 2 February 4th 09 02:25 PM
cell alignment hjc Excel Discussion (Misc queries) 6 April 16th 08 03:20 AM
Cell Alignment TripleT[_4_] Excel Programming 1 February 20th 04 03:12 AM


All times are GMT +1. The time now is 12:26 AM.

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

About Us

"It's about Microsoft Excel"