|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
回复 1楼 dushuqiang 的帖子
来个全的,合并与分解。
Sub Splitcontent() '分解单元格
For a = [B65536].End(xlUp).Row To 2 Step -1
b = UBound(Split(Range("B" & a).Value, "、")) '取分隔符
If b > 0 Then
Cells(a, 1).Offset(1, 0).Resize(b, 1).EntireRow.Insert '在第当前行以下插入b行,Resize为扩展区域
Range(a + 1 & ":" & a + b) = Range(a & ":" & a).Value '复制行
s = Split(Range("B" & a).Value, "、") '指定分隔符
For c = b To 0 Step -1
Range("B" & a).Offset(c, 0).Value = s(c)
Next
End If
Next
End Sub
Sub MergeSameCells() '合并单元格
Dim Irow As Integer, m%
Dim s As String, c As Range
Application.DisplayAlerts = False
With ActiveSheet '合并第一列
Irow = .Range("A65536").End(xlUp).Row
For i = Irow To 2 Step -1
If .Cells(i, 1).Value = .Cells(i - 1, 1).Value Then
.Range(.Cells(i - 1, 1), Cells(i, 1)).Merge
End If
Next
End With
Application.DisplayAlerts = True
For i = 3 To [b65535].End(xlUp).Row - 1
j = Cells(i, 1).MergeArea.Count
Range(Cells(i, 2), Cells(i + j - 1, 2)).Select
For Each c In Selection '合并第二列
s = s & c.Value & "、"
Next
Application.DisplayAlerts = False
Selection.Merge
m = UBound(Split(s, "、"))
s = Application.WorksheetFunction.Substitute(s, "、", "", m)
Selection.Value = s
Application.DisplayAlerts = True
If j <> 1 Then Rows(i + 1 & ":" & i + j - 1).Delete
s = ""
If Cells(i, 1) = "" Then Exit For
Next
End Sub |
|