|
bluexuemei 发表于 2013-4-16 23:48
学习取消合并单元格的方法,收藏!
附上两段代码,第一个是合并B列相同内容的单元格,第二个是第一个的相反过程以供大家共同学习!
第一个:
Sub a()
Dim i As Integer
Dim introw As Integer
Application.DisplayAlerts = False
With Sheet1
introw = .Range("b65336").End(xlUp).Row
For i = introw To 2 Step -1
If .Cells(i, 2).Value = .Cells(i - 1, 2).Value Then
.Range(Cells(i, 2), Cells(i - 1, 2)).Merge
End If
Next
End With
Application.DisplayAlerts = True
End Sub
第二个
Sub b()
Dim i As Integer
Dim introw As Integer
Dim intcot As Integer
Dim str As String
Application.DisplayAlerts = False
introw = Sheet1.Range("b65336").End(xlUp).Row
With Sheet1
For i = 2 To introw
str = .Cells(i, 2).Value
intcot = .Cells(i, 2).MergeArea.Count
.Cells(i, 2).UnMerge
.Range(Cells(i, 2), Cells(i + intcot - 1, 2)).Value = str
i = i + intcot - 1
Next
Application.DisplayAlerts = True
End With
End Sub
这里顺便指出一些事情,以待大家思考:
1.intcot = .Cells(i, 2).MergeArea.Count中这个mergearea.count,EXCEL是怎么数出来的呢?
2.如果我的B列形式如下;
财务
会计
会计
财务
我怎么能使财务的都合到一起呢??
|
|