你可以"合并下来"在Excel?

时间:2015-10-30 01:08:15

标签: excel excel-vba vba

Excel有一个" Merge Across"内置的函数允许您突出显示一个范围,然后自动合并每一行中的所有单元格,但不合并行本身(主要用于报表)。你能在专栏上做同样的事吗?

1 个答案:

答案 0 :(得分:4)

Excel不支持" Merge Down"本身。我为函数写了一个宏:

Sub MergeDown()

Dim i As Integer, NumCols As Integer, NumRows As Integer, _
    LocX As Integer, LocY As Integer

LocX = Selection.Column
LocY = Selection.Row
NumCols = Selection.Columns.Count
NumRows = Selection.Rows.Count

For i = 1 To NumCols
    Range(Cells(LocY, LocX + i - 1), Cells(LocY + NumRows - 1, _
        LocX + i - 1)).Select
        On Error GoTo ErrorHandler
    Selection.Merge
Next

Exit Sub

ErrorHandler: Exit Sub

End Sub

PS:你真的不应该合并单元格,因为它很难处理工作表。