|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 合并()
With Sheets("sheet2")
r = .Cells(Rows.Count, 3).End(xlUp).Row
y = .Cells(2, Columns.Count).End(xlToLeft).Column
ar = .Range(.Cells(1, 3), .Cells(r, y))
End With
ReDim br(1 To UBound(ar), 1 To 1)
For i = 3 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
n = n + 1
For j = 2 To UBound(ar, 2) - 1
If Trim(ar(1, j)) = "基本项" Then
If br(n, 1) = "" Then
br(n, 1) = ar(i, 1) & ":" & Chr(10) & "[基本项目]" & Chr(10) & ar(2, j) & ":" & ar(i, j)
Else
br(n, 1) = br(n, 1) & Chr(10) & ar(2, j) & ":" & ar(i, j)
End If
End If
Next j
k = 0
For j = 2 To UBound(ar, 2) - 1
If Trim(ar(1, j)) = "扣款项" Then
k = k + 1
If k = 1 Then
br(n, 1) = br(n, 1) & ":" & Chr(10) & "[扣款项]" & Chr(10) & ar(2, j) & ":" & ar(i, j)
Else
br(n, 1) = br(n, 1) & Chr(10) & ar(2, j) & ":" & ar(i, j)
End If
End If
Next j
br(n, 1) = br(n, 1) & Chr(10) & ar(2, UBound(ar, 2)) & ":" & ar(i, UBound(ar, 2))
End If
Next i
With Sheets("合并")
.[a1].CurrentRegion = Empty
.[a1].Resize(n, 1) = br
End With
MsgBox "ok!"
End Sub
|
|