我正在尝试合并第 1 行的每 3 个单元格(从 B1 开始,最后一个要合并的单元格是 FY - 意味着应该合并 FW、FX 和 FY。)。我已经使用它来合并一列中的每 3 行,但是我如何更改它以跨越第 1 行?
Function MergeHeaders()
Application.DisplayAlerts = False
Dim RgToMerge As Range
For i = 3 To ActiveSheet.Cells(Rows.Count, 3).End(xlUp).Row Step 3
Set RgToMerge = Range(Cells(i, 3), Cells(i + 1, 3))
With RgToMerge
.Merge
.HorizontalAlignment = xlCenterAcrossSelection
.VerticalAlignment = xlCenter
End With
Next i
End Function
最佳答案
还有类似的东西吗?
Function MergeHeaders()
Dim RgToMerge As Range
Application.DisplayAlerts = False
For i = 2 To ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column Step 3
Set RgToMerge = Range(Cells(1, i), Cells(1, i + 2))
With RgToMerge
.Merge
.HorizontalAlignment = xlCenterAcrossSelection
.VerticalAlignment = xlCenter
End With
Next i
End Function
关于vba - 合并第 1 行中的每 3 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41043254/