gpt4 book ai didi

vba - 合并第 1 行中的每 3 行

转载 作者:行者123 更新时间:2023-12-02 17:42:58 25 4
gpt4 key购买 nike

我正在尝试合并第 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com