This code works great until the last column is blank. So the last column in row 22 is blank and should be merged with column 21. Colum 22 has data, but row 22 doesn't. It's reading the last column as the end of the spreadsheet. I've tried to play around with the changing the last column calculation to a different row, but no luck. Thanks for the help!
VBA Code:
Dim c3 As Long, c4 As Long
c3 = 3
Do
If .Cells(22, c3 + 1) = "" Then
c4 = .Cells(22, c3).End(xlToRight).Column
If c4 < Columns.Count Then
.Range(.Cells(22, c3), .Cells(31, c4 - 1)).HorizontalAlignment = xlCenterAcrossSelection
c3 = c4
Else
Exit Do
End If
Else
c3 = c3 + 1
End If
Loop
End With