|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 筛选()
Application.ScreenUpdating = False
Dim ar As Variant
Dim br()
With Sheets("Sheet1")
r = .Cells(Rows.Count, 1).End(xlUp).Row
ar = .Range(.Cells(1, 1), .Cells(r, 16))
h_1 = .[b1]
End With
Set sh = ThisWorkbook.Worksheets("Sheet3")
With sh
rs = .Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To rs
n = 0
ReDim br(1 To UBound(ar), 1 To UBound(ar, 2))
y = .Cells(i, Columns.Count).End(xlToLeft).Column
For j = 2 To y
If Trim(.Cells(i, j)) <> "" Then
zd = zd & .Cells(i, j)
For s = 2 To UBound(ar)
If InStr(ar(s, 1), .Cells(i, j)) > 0 Then
n = n + 1
For jj = 1 To UBound(ar, 2)
br(n, jj) = ar(s, jj)
Next jj
End If
Next s
End If
Next j
If n > 0 Then
For s = 1 To n
If Trim(br(s, 1)) <> "" Then
br(s, 4) = br(s, 5) & h_1 & .Cells(i, 2) & s
End If
Next s
Sheets("sheet1").Copy
Set wb = ActiveWorkbook
With wb.Worksheets(1)
.Range("a2:q" & r) = Empty
.[a2].Resize(n, UBound(br, 2)) = br
End With
wb.SaveAs Filename:=ThisWorkbook.Path & "\" & .Cells(i, 1) & ".xlsx"
wb.Close
End If
Next i
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|