|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 按钮1_Click()
Application.ScreenUpdating = False
Dim ar As Variant, br As Variant
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("数据A")
r = .Cells(Rows.Count, 1).End(xlUp).Row
y = .Cells(1, Columns.Count).End(xlToLeft).Column
ar = .Range(.Cells(1, 1), .Cells(r, y))
End With
For j = 1 To UBound(ar, 2)
If Trim(ar(1, j)) <> "" Then
d(Trim(ar(1, j))) = j
End If
Next j
With Sheets("数据B")
rb = .Cells(Rows.Count, 1).End(xlUp).Row
yb = .Cells(1, Columns.Count).End(xlToLeft).Column
br = .Range(.Cells(1, 1), .Cells(rb, yb))
End With
ReDim arr(1 To UBound(ar) + UBound(br) + 1000, 1 To UBound(ar, 2) + UBound(br, 2))
yy = 1
arr(1, 1) = "数据源"
For j = 1 To UBound(br, 2)
n = 1
If Trim(br(1, j)) <> "" Then
lh = d(Trim(br(1, j)))
If lh <> "" Then
yy = yy + 1
arr(1, yy) = br(1, j)
For i = 2 To UBound(ar)
n = n + 1
arr(n, yy) = ar(i, lh)
arr(n, 1) = "数据A"
Next i
For i = 2 To UBound(br)
n = n + 1
arr(n, yy) = br(i, j)
arr(n, 1) = "数据B"
Next i
End If
End If
Next j
With Sheets("汇总")
.[a1].CurrentRegion = Empty
If yy = 1 Or n = 1 Then MsgBox "没有需要提取的数据!": End
.[a1].Resize(n, yy) = arr
End With
Set d = Nothing
MsgBox "ok!"
End Sub
|
评分
-
1
查看全部评分
-
|