View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Peter T[_3_] Peter T[_3_] is offline
external usenet poster
 
Posts: 81
Default How to justify in merged cells

It's one of the few times I recommend using Select.

Is it necessary to Select? This worked for me:

Sub test()
Dim objSheet As Worksheet
Set objSheet = Worksheets("Sheet3")
With objSheet.Range("A1:E1")
..Clear
..HorizontalAlignment = xlCenterAcrossSelection
..VerticalAlignment = xlVAlignCenter
'.BorderAround 1 ' and whatever
..Cells(1).Value = "My Report Title"
End With
End Sub

Regards,
Peter

-----Original Message-----
I detest merging, since it screws up selections,

formatting, sorting,
etc. I'd suggest instead that you center across A1:E1.

Something like
this:

Dim rOldSelection As Range

Application.ScreenUpdating = False
Set rOldSelection = Selection
Application.Goto objSheet.Range("A1:E1")
With Selection
.Item(1).Value = "My Title"
.HorizontalAlignment = xlCenterAcrossSelection
End With
Application.Goto rOldSelection
Application.ScreenUpdating = True

It's one of the few times I recommend using Select.


In article ,
"Bill Murphy" wrote:

I have merged 5 cells horizontally with:

objSht.Range("A1:E1").Merge
objSht.Cells(1, 1) = "My Report Title"

How can I center the report title in the merged cells?

.