如何合并基于类似值的单元格 - Excel 2010 [英] How to merge cells based on similar values - Excel 2010
问题描述
我有一个问题,合并Excel中的单元格类似的值为一列 - 我想保留其他列数据 - 让我们查看一些截图,它将会更清楚:
I have a problem merging cells in excel based on similar values for one column- I would like to keep other columns data - let's view some screenshots and it will be clearer:
以上是数据的初始状态,
我想要实现的是:
This above is the initial state of the Data, what I want to achieve is this:
我确定有一种方法可以用VB或公式来做 - 我需要最简单的方法,因为这是一个客户,它需要很容易。
I'm sure there is a way to do it with VB or formulas- I need the most simple way possible as this is for a customer and it needs to be easy.
谢谢大家的高级。
推荐答案
Option Explicit
Private Sub MergeCells()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim rngMerge As Range, cell As Range
Set rngMerge = Range("A1:A100") 'Set the range limits here
MergeAgain:
For Each cell In rngMerge
If cell.Value = cell.Offset(1, 0).Value And IsEmpty(cell) = False Then
Range(cell, cell.Offset(1, 0)).Merge
GoTo MergeAgain
End If
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
您可以对范围限制(即用于检查列A中的最后一行),每次都有用户输入,或以编程方式查找范围中的最后一行。无论如何,这应该让你开始。
You can hardcode the range limits (i.e. the last row in Column A to check), have the user input it each time, or programmatically find the last row in the range . Either way, this should get you started.
顺便说一句,你可以在A列中找到最后一行如下:
By the way, you could find the last row in column A with the following:
Dim i As Integer
i = Range("A1").End(xlDown).Row
Set rngMerge = Range("A1:A" & i)
这篇关于如何合并基于类似值的单元格 - Excel 2010的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!