我有一个包含大量数据的电子表格。大约一半的单元格与其他单元格水平合并,并包含名称,例如John Doe。有人知道如何编写一个宏来取消合并单元格,同时将单元格的值分配给所有先前合并的单元格吗?干杯杰克
编辑:我这样做的原因是检查两个相邻的单元格是否相等,即A1 = A2。但是当两个单元格合并时,我会遇到问题。如果有人知道解决这个问题的方法,而不用分离单元格和复制数据,那就更好了!
发布于 2013-06-19 06:52:18
我在下面提供的想法已经在Excel2010VBA 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以及呈现结果之前和之后的图片:

发布于 2015-01-16 08:15:57
我从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 subhttps://stackoverflow.com/questions/17158189
复制相似问题