1

您好,我想将第 1 行的七个单元格合并在一起。我想我可以通过宏来实现这一点,而不是单击 A1 按 shift,然后按右箭头键六次。我已经写了以下内容,但不确定如何在字母参考中添加 7,尤其是当我进入以 AA1 结尾的最后七个时,它会启动 AA2 并继续。下面的代码实现了我想要的,但是我如何引入变量和一个循环来将字母存储为 int,加六,然后转换回字符串并继续下一组?我该怎么写While (End of row has not been reached)

Range("A1:G1").Select
With Selection
    .HorizontalAlignment = xlGeneral
    .VerticalAlignment = xlBottom
    .WrapText = False
    .Orientation = 0
    .AddIndent = False
    .IndentLevel = 0
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .MergeCells = True
End With

Range("H1:N1").Select
    With Selection
    .HorizontalAlignment = xlGeneral
    .VerticalAlignment = xlBottom
    .WrapText = False
    .Orientation = 0
    .AddIndent = False
    .IndentLevel = 0
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .MergeCells = True
End With
4

1 回答 1

1

这是你正在尝试的吗?

'R1 is the row of the first cell
'C1 is the column of the first cell
'R2 is the row of the second cell
'C2 is the column of the second cell

Sub Sample()
    Dim Rng As Range
    Dim ws As Worksheet
    Dim R1 As Long, C1 As Long
    Dim R2 As Long, C2 As Long

    Set ws = ThisWorkbook.Sheets("Sheet1")

    R1 = 1: C1 = 1
    R2 = 1: C2 = C1 + 6

    With ws
        Set Rng = .Range(.Cells(R1, C1), .Cells(R2, C2))
        Application.DisplayAlerts = False
        Rng.Merge
        Application.DisplayAlerts = True
    End With
End Sub

编辑:您可能还会发现链接很有趣。

于 2013-10-18T13:56:49.310 回答