|
Option Explicit
Sub TEST6()
Dim ar, br, i&, j&, r&, n&, dic As Object, strInput$, iPosCol&, wks As Worksheet
Application.ScreenUpdating = False
strInput = InputBox("请输入关键字:", "名称", "华为")
If strInput = "" Then Exit Sub
Set dic = CreateObject("Scripting.Dictionary")
With [A1].CurrentRegion
.Offset(1).Clear
ar = .Resize(10 ^ 3)
For i = 1 To UBound(ar, 2): dic(ar(1, i)) = i: Next
r = 1
End With
For Each wks In Sheets
If wks.Name <> ActiveSheet.Name Then
With wks
br = .[A1].CurrentRegion
For i = 2 To UBound(br)
n = 0
For j = 1 To UBound(br, 2)
If br(i, j) = strInput Then
n = i: Exit For
End If
Next j
If n <> 0 Then
r = r + 1
For j = 1 To UBound(br, 2)
If dic.exists(br(1, j)) Then
iPosCol = dic(br(1, j))
ar(r, iPosCol) = br(i, j)
End If
Next j
ar(r, UBound(ar, 2)) = .Name
End If
Next i
End With
End If
Next wks
With [A1].Resize(r, UBound(ar, 2))
.Columns(1).NumberFormatLocal = "00"
.Columns(2).NumberFormatLocal = "yyyy-m-d"
.Columns(5).NumberFormatLocal = "000"
.Columns("F:I").NumberFormatLocal = "0.00"
.Value = ar
.HorizontalAlignment = xlCenter
.Borders.LineStyle = xlContinuous
.Font.Size = 10
End With
Set dic = Nothing
Application.ScreenUpdating = True
Beep
End Sub
|
|