答案1
试试这个代码:
Sub Test() TitleRow = 1 'if title contain more than one row, change the value 1 to the actual number of rows i = 0 Application.DisplayAlerts = False Do Set StartCell = ActiveSheet.Range("A" & (TitleRow + 3 * i + 1)) Set EndCell = ActiveSheet.Range("A" & (TitleRow + 3 * i + 3)) With ActiveSheet.Range(StartCell, EndCell) .Merge .VerticalAlignment = xlCenter .HorizontalAlignment = xlCenter End With i = i + 1 Loop Until Range("A" & (TitleRow + 3 * i) + 1) = "" Application.DisplayAlerts = True End Sub
答案2
可以使用宏或 VBA 轻松完成,根据您的要求在 VBA 中编辑以下代码。
范围(“A1:A3”)。选择所选内容。HorizontalAlignment = xlCenter 。VerticalAlignment = xlBottom 。WrapText = False 。Orientation = 0 。AddIndent = False 。IndentLevel = 0 。ShrinkToFit = False 。ReadingOrder = xlContext 。MergeCells = False 以选择结束。与选择合并。HorizontalAlignment = xlCenter