|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
在Sheet1中存放数据,Sheet 2中列好标题,然后运行下列程序可实现
Sub 父层子层()
Application.ScreenUpdating = False
Dim rw As Integer, rw1 As Integer, m As Integer
'rw为Sheet1中行号,rw1为Sheet2中行号,m为Sheet2中列号
rw = 2
rw1 = 1
For rw = 2 To Sheets("Sheet1").Cells(1, 1).End(xlDown).Row
If Sheets("Sheet1").Cells(rw, 3) = "成品" Then
'遇到成品rw1+1行
rw1 = rw1 + 1
Sheets("Sheet2").Cells(rw1, 1) = Sheets("Sheet1").Cells(rw, 2)
Else
m = Application.Match(Sheets("Sheet1").Cells(rw, 3), Sheets("Sheet2").Range("a1:d1"), 0)
'在确认行数后,用Match函数判断列数
If m > 0 Then
Sheets("Sheet2").Cells(rw1, m) = Sheets("Sheet1").Cells(rw, 2)
End If
End If
Next
Application.ScreenUpdating = False
End Sub
|
|