【问题标题】:Unmerge cells and distribute contents in Excel (for mac) 2011在 Excel (for mac) 2011 中取消合并单元格并分发内容
【发布时间】:2013-06-17 22:56:50
【问题描述】:

我有一个包含大量数据的电子表格。大约一半的单元格与其他单元格水平合并,并包含名称,例如约翰·多伊。 有谁知道如何编写一个宏来取消合并单元格,同时将单元格的值分配给之前合并的所有单元格? 干杯 杰克

编辑:我这样做的原因是检查两个相邻单元格是否相等,即 A1 = A2。但是当任一单元格被合并时我遇到了问题。如果有人知道解决此问题的方法,而无需分离单元格并复制数据,那就更好了!

【问题讨论】:

    标签: excel merge spreadsheet vba


    【解决方案1】:

    我在下面提供的想法已针对 Excel 2010 VBA Win7 进行了测试。但是,我不确定我是否希望它也适用于 Mac(因为这是Range object 的一组标准属性和方法)。如果这不起作用,请告诉我删除我的答案。

    这个简单的代码适用于选定的区域,但是很容易将其更改为任何其他范围。下面代码中的一些其他注释。

    Sub Unmerging_Selection()
    
        Dim tmpAddress As String
        Dim Cell As Range
    
        'change Selection below for any other range to process
        For Each Cell In Selection
    
            'check if cell is merged
            If Cell.MergeCells Then
                'if so- check the range merged
                tmpAddress = Cell.MergeArea.Address
                'umnerge
                Cell.UnMerge
                'put the value of the cell to
                Range(tmpAddress) = Cell
            End If
        Next
    
    End sub
    

    以及结果前后呈现的图片:

    【讨论】:

    • 干杯!我没有在正确的计算机上进行检查,但我会尽快回复您!您是否知道这是否也适用于 google docs 电子表格程序?
    【解决方案2】:

    我能够从 KazJaw 获得解决方案,通过一次编辑在 Mac 上工作,将 Cell.UnMerge 更改为 ActiveSheet.UsedRange.MergeCells = False,由 Ron Debruin 提供:http://www.rondebruin.nl/mac/mac027.htm

    Sub Unmerging_Selection()
    
    Dim tmpAddress As String
    Dim Cell As Range
    
    'change Selection below for any other range to process
    For Each Cell In Selection
    
        'check if cell is merged
        If Cell.MergeCells Then
            'if so- check the range merged
            tmpAddress = Cell.MergeArea.Address
            'umnerge
            ActiveSheet.UsedRange.MergeCells = False
            'put the value of the cell to
            Range(tmpAddress) = Cell
        End If
    Next
    
    End sub
    

    【讨论】:

      猜你喜欢
      • 2022-12-07
      • 2016-01-27
      • 1970-01-01
      • 2015-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-17
      • 2021-05-10
      相关资源
      最近更新 更多