View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
stone stone is offline
external usenet poster
 
Posts: 1
Default Convert "merged" cells to "CenterAcrossSelection"

I need a function that would loop through all the cells in the used range of a single sheet and convert any merged cells to "xlCenterAcrossSelection" for the same range as the cells that were originally merged

For example, if the range "B2:J2" was merged, convert range "B2:J2" to centered across the selection

My code (below) unmerges the cells but then fails to convert them to "center across"

Dim rngCell As Rang
For Each rngCell In ActiveSheet.UsedRang
If rngCell.MergeCells = True The
Selection.UnMerg
Selection.HorizontalAlignment = xlCenterAcrossSelection <this line fails without any error
End I
Next rngCel

Could someone please correct my code and/or show me example code that would accomplish what I'm trying to do

TIA