1

こんにちは、行 1 全体で 7 つのセルを結合したいと思います。Shift キーを押しながら A1 をクリックし、右矢印キーを 6 回押す代わりに、マクロを使用してこれを実現できると考えています。私は次のように書いていますが、文字の参照に 7 を追加する方法がわかりません。特に、AA1 で終わる最後の 7 に入ると、AA2 が開始されて続きます。次のコードは私が望むものを実現しますが、変数とループを導入して文字を int として保存し、6 を追加してから文字列にキャストし直して次のセットに進むにはどうすればよいでしょうか? どのように書きますか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 に答える