|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Option Explicit
Sub 查询()
Dim ar, br, i&, j&, r&, N&, dic As Object, strInput$, iPosCol&, wks As Worksheet
Sheets("查询").Select
Application.ScreenUpdating = False
strInput = InputBox("请输入关键字:", "名称")
If strInput = "" Then Exit Sub
Set dic = CreateObject("Scripting.Dictionary")
With [a4].CurrentRegion
.Offset(1).Clear
ar = .Resize(12 ^ 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 Instr(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 [a4].Resize(r, UBound(ar, 2))
.Columns(1).NumberFormatLocal = "0000"
.Columns(2).NumberFormatLocal = "yyyy-mm-dd"
.Columns(5).NumberFormatLocal = "@"
.Columns("F:h").NumberFormatLocal = "0.00"
.Value = ar
.HorizontalAlignment = xlCenter
.Borders.LineStyle = xlContinuous
.Font.Size = 10
End With
Set dic = Nothing
Application.ScreenUpdating = True
Beep
End Sub |
评分
-
1
查看全部评分
-
|