0

我正在尝试在不断变化的位置选择一组行进行合并。我似乎无法弄清楚。我已经在谷歌搜索了半个小时,尝试了不同的方法。这样我就可以合并和格式化新组合的 9 个单元格。它已经在一个按钮下,并且将从用户表单中提取信息。我正在寻找的是如何设置范围。我愿意接受所有建议,提前感谢。

Worksheets("CompList").Cells(Rows.Count, 1).End(xlUp).Select    'selects last row of information in row "A"
Cells(Selection.Row + BusHeight, Selection.Column).Select       'adds number of lines for business to add to get next empty slot

Selection.Value = 1 'listdivision.Value
    Range(Cells(Selection.Row, Selection.Column), Cells(Selection.Row + 1, Selection.Column), Cells(Selection.Row + 1, Selection.Column), Cells(Selection.Row + 1, Selection.Column), Cells(Selection.Row + 1, Selection.Column), Cells(Selection.Row + 1, Selection.Column), Cells(Selection.Row + 1, Selection.Column), Cells(Selection.Row + 1, Selection.Column)).Select

With Selection
    .HorizontalAlignment = xlLeft
    .VerticalAlignment = xlTop
    .WrapText = False
    .Orientation = 0
    .AddIndent = False
    .IndentLevel = 0
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .MergeCells = True
End With
4

1 回答 1

0

这是你正在尝试的吗?

Sub Sample()
    Dim ws As Worksheet
    Dim LRow As Long, BusHeight As Long
    Dim Rng As Range

    Set ws = ThisWorkbook.Worksheets("CompList")

    BusHeight = 9

    With ws
        LRow = .Range("A" & .Rows.Count).End(xlUp).Row + 1

        Set Rng = .Range(.Cells(LRow, 1), .Cells(LRow - 1 + BusHeight, 1))

        With Rng
            .HorizontalAlignment = xlLeft
            .VerticalAlignment = xlTop
            .ReadingOrder = xlContext
            .MergeCells = True
            .Value = 1
        End With
    End With
End Sub
于 2013-11-09T06:28:14.890 回答