This code merges cells in multiple columns on multiple sheets, and it's too slow.
I'm hoping for any help at all to speed this up. Unfortunately, I'm not able to get around the fact that the cells must be merged.
I broke up the for statements - it helped a bit, but it's still very, very slow.
Also, I turned off screenupdating, events, calculation, displaypagesbreaks, etc.; it didn't seem to help.
Function MergeCells()
Dim WS_Count As Integer
Dim i As Integer
Dim ShName As String
WS_Count = ActiveWorkbook.Worksheets.Count
PIS.Activate
For i = 1 To WS_Count
Select Case ActiveWorkbook.Worksheets(i).Name
Case "Med Curr", "Med Ren", "Med RevRen", "Med Prop", "Med Renewal Alts A", "Med Renewal Alts B", _
"Med Renewal Alts C", "Med Prop Other Markets 1A", "Med Prop Other Markets 1B", "Med Prop Other Markets 1C", _
"Med Prop Other Markets 2A", "Med Prop Other Markets 2B", "Med Prop Other Markets 2C", _
"Med Prop Other Markets 3A", "Med Prop Other Markets 3B", "Med Prop Other Markets 3C"
ActiveWorkbook.Worksheets(i).Activate
ShName = ActiveSheet.Name
MergeCellsx (ShName)
End Select
Next i
End Function
Function MergeCellsx(ShName)
Dim RngB As Range
Dim row As Integer
With Sheets(ShName)
For row = 6 To 12
Set RngB = .Range(.Cells(row, 2), .Cells(row, 3))
RngB.Merge
RngB.HorizontalAlignment = xlCenter
Set RngB = .Range(.Cells(row, 5), .Cells(row, 6))
RngB.Merge
RngB.HorizontalAlignment = xlCenter
Set RngB = .Range(.Cells(row, 8), .Cells(row, 9))
RngB.Merge
RngB.HorizontalAlignment = xlCenter
Next row
For row = 14 To 18
Set RngB = .Range(.Cells(row, 2), .Cells(row, 3))
RngB.Merge
RngB.HorizontalAlignment = xlCenter
Set RngB = .Range(.Cells(row, 5), .Cells(row, 6))
RngB.Merge
RngB.HorizontalAlignment = xlCenter
Set RngB = .Range(.Cells(row, 8), .Cells(row, 9))
RngB.Merge
RngB.HorizontalAlignment = xlCenter
Next row
For row = 20 To 22
Set RngB = .Range(.Cells(row, 2), .Cells(row, 3))
RngB.Merge
RngB.HorizontalAlignment = xlCenter
Set RngB = .Range(.Cells(row, 5), .Cells(row, 6))
RngB.Merge
RngB.HorizontalAlignment = xlCenter
Set RngB = .Range(.Cells(row, 8), .Cells(row, 9))
RngB.Merge
RngB.HorizontalAlignment = xlCenter
Next row
For row = 24 To 25
Set RngB = .Range(.Cells(row, 2), .Cells(row, 3))
RngB.Merge
RngB.HorizontalAlignment = xlCenter
Set RngB = .Range(.Cells(row, 5), .Cells(row, 6))
RngB.Merge
RngB.HorizontalAlignment = xlCenter
Set RngB = .Range(.Cells(row, 8), .Cells(row, 9))
RngB.Merge
RngB.HorizontalAlignment = xlCenter
Next row
For row = 27 To 34
Set RngB = .Range(.Cells(row, 2), .Cells(row, 3))
RngB.Merge
RngB.HorizontalAlignment = xlCenter
Set RngB = .Range(.Cells(row, 5), .Cells(row, 6))
RngB.Merge
RngB.HorizontalAlignment = xlCenter
Set RngB = .Range(.Cells(row, 8), .Cells(row, 9))
RngB.Merge
RngB.HorizontalAlignment = xlCenter
Next row
End With
End Function
Set RngB = .Range(.Cells(row, 2), .Cells(row, 3))that could become a its ownSub MergeAndCenter(ByVal ws as worksheet, ByVal rw as Long, ByVal cl as Long). It would at least make future edits easier and your code quite a bit neater. \$\endgroup\$Center Across Selection? \$\endgroup\$