取消优化行,并重复数据 [英] Unmerging excel rows, and duplicate data

查看:145
本文介绍了取消优化行,并重复数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经给了一个相当大的数据库存储在Microsoft Excel中,我必须尝试转换成有用的东西。

但是,我遇到的一个问题是一些数据是合并在一起(水平在2s)。



例如;

 行1:[x] [x] [x] [x] [x] 
行2:[x] [x] [oo] [x]
行3:[oo] [x] [oo]

其中x是单个单元格,o合并在一起



我想做的是取消合并所有的行(我可以用unmerge按钮来做相当简单的),但是对于合并单元格的位置,在2个单元格中复制数据。

从; [[Some Data]]

To; [Some Data] [Some Data]



谢谢!任何帮助都不胜感激。

解决方案

这是一个VBA解决方案。此宏将搜索活动工作表中的每个单元格,以查看它们是否合并。如果它们是,它将合并的单元格的范围存储在温度。范围变量,取消合并单元格,然后使用未合并范围内的第一个单元格的值填充范围(该值为什么)。



  Sub UnMergeFill()

Dim cell As Range,joinedCells As Range

For Each cell In ThisWorkbook.ActiveSheet.UsedRange
如果cell.MergeCells然后
设置joinedCells = cell.MergeArea
cell.MergeCells = False
joinedCells.Value = cell.Value
End If
下一个

End Sub


I have been given a fairly large database stored in Microsoft Excel, which I have to try convert into something useful.
However, one of the problems that I am encountering is that some of the data is merged together (horizontally in 2s).

For example;

row 1: [ x ][ x ][ x ][ x ][ x ]
row 2: [ x ][ x ][ o    o ][ x ]
row 3: [ o    o ][ x ][ o    o ]

Where x's are single cells and o's are merged together

What I want to do is unmerge all the rows (which I could do fairly easy with the unmerge button), but for where the merged cell was, have the data duplicated across the 2 cells.
From; [[ Some Data ]]
To; [ Some Data ][ Some Data ]

Thanks! Any help is appreciated.

解决方案

This is a VBA solution. This macro will search every cell in the active sheet to see if they are merged. If they are, it stores the range of the merged cells in a temp. range variable, unmerges the cells, then fills the range with the value of the first cell in the unmerged range (what the value was).

Sub UnMergeFill()

Dim cell As Range, joinedCells As Range

For Each cell In ThisWorkbook.ActiveSheet.UsedRange
    If cell.MergeCells Then
        Set joinedCells = cell.MergeArea
        cell.MergeCells = False
        joinedCells.Value = cell.Value
    End If
Next

End Sub

这篇关于取消优化行,并重复数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆