excel - 使用合并的单元格对行进行排序

标签 excel vba merge

通常我会避免使用合并的单元格,但我们从管理软件中获得了类似这样的表格:

example

我发现最简单的过程是取消合并、排序,然后再次合并,但使用 header到表和sheet number of sheets它变得乏味。融合的单元格是已知的(I+J,M+N),表格从第 11 行开始,因此设置了页面。

我调整了一个执行 unmerge 然后合并部分但需要对其进行排序的代码,并且有比这更干净的代码

Sub Merge_fused()
    '~~> unmerged range
    Dim MyRange As Range
    Set MyRange = Range("H11:X56")
    '~~> merged columns
    Dim IRange As Range
    Set IRange = Range("I11:J56")
    Dim MRange As Range
    Set MRange = Range("M11:N56")
    Dim VRange As Range
    Set VRange = Range("V11:W56")

    On Error Resume Next

    With MyRange
        .UnMerge
    End With

    '~~> i need to sort MyRange here

    With IRange
        .Merge True
    End With

    With MRange
        .Merge True
    End With

    With VRange
        .Merge True
    End With
End Sub

最佳答案

我知道这有点老,但我只是遇到了这个并让代码为我工作。
我在上面写着 '~~> i need to sort here the MyRange here 的地方添加了这段代码

projp.Range("your range").Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlNo

非常适合我

关于excel - 使用合并的单元格对行进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21768088/

相关文章:

c# - 根据客人数量的最大计数合并重叠间隔

vba - Excel 查找和替换宏

excel - 我想在 Excel 中的一行文本单元格中添加一组升序数字

Excel COUNTIF 表示范围内的逗号分隔值

algorithm - 合并 k 个列表的最佳方式是什么?

python - 根据两个不同大小的数据帧更新列并更新第一个数据帧中的值。 (python中vlookup的概念)

excel - 将两个不同工作簿中的两个范围粘贴到 Outlook 邮件正文中

excel - 查找 ListObject 中的最后一个可见行

excel - 最大化打开 Excel 电子表格

VBA 工作表子在另一个工作表中创建命名范围